mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00:00
Refactor fallback handling in getent()
This patch factors out the fgetint() fallback code for parsing /etc/services and /etc/protocols. Useful on systems with a malfunctioning C library. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
5cc98f6e53
commit
bb89bdd8a9
1 file changed
+27
-7
@@ -321,9 +321,8 @@ void inetd_stop(inetd_t *inetd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct servent *getent_service(char *service, char *proto)
|
static struct servent *fallback_service(char *service, char *proto)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_STATIC
|
|
||||||
int service_num;
|
int service_num;
|
||||||
static struct servent lfs;
|
static struct servent lfs;
|
||||||
|
|
||||||
@@ -339,14 +338,24 @@ static struct servent *getent_service(char *service, char *proto)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
#else
|
|
||||||
return getservbyname(service, proto);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct protoent *getent_proto(char *proto)
|
static struct servent *getent_service(char *service, char *proto)
|
||||||
{
|
{
|
||||||
|
struct servent *ent;
|
||||||
|
|
||||||
#ifdef ENABLE_STATIC
|
#ifdef ENABLE_STATIC
|
||||||
|
ent = fallback_service(service, proto);
|
||||||
|
#else
|
||||||
|
ent = getservbyname(service, proto);
|
||||||
|
if (!ent)
|
||||||
|
ent = fallback_service(service, proto);
|
||||||
|
#endif
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct protoent *fallback_proto(char *proto)
|
||||||
|
{
|
||||||
int proto_num;
|
int proto_num;
|
||||||
static struct protoent lfp;
|
static struct protoent lfp;
|
||||||
|
|
||||||
@@ -359,9 +368,20 @@ static struct protoent *getent_proto(char *proto)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct protoent *getent_proto(char *proto)
|
||||||
|
{
|
||||||
|
struct protoent *ent;
|
||||||
|
|
||||||
|
#ifdef ENABLE_STATIC
|
||||||
|
ent = fallback_proto(proto);
|
||||||
#else
|
#else
|
||||||
return getprotobyname(proto);
|
ent = getprotobyname(proto);
|
||||||
|
if (!ent)
|
||||||
|
ent = fallback_proto(proto);
|
||||||
#endif
|
#endif
|
||||||
|
return ent;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getent(char *service, char *proto, struct servent **sv, struct protoent **pv)
|
static int getent(char *service, char *proto, struct servent **sv, struct protoent **pv)
|
||||||
|
|||||||
Reference in new issue
Block a user