mirror of
https://github.com/troglobit/finit.git
synced 2026-10-29 12:40:44 +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
+36
-16
@@ -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,29 +338,50 @@ static struct servent *getent_service(char *service, char *proto)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct servent *getent_service(char *service, char *proto)
|
||||||
|
{
|
||||||
|
struct servent *ent;
|
||||||
|
|
||||||
|
#ifdef ENABLE_STATIC
|
||||||
|
ent = fallback_service(service, proto);
|
||||||
#else
|
#else
|
||||||
return getservbyname(service, proto);
|
ent = getservbyname(service, proto);
|
||||||
|
if (!ent)
|
||||||
|
ent = fallback_service(service, proto);
|
||||||
#endif
|
#endif
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct protoent *fallback_proto(char *proto)
|
||||||
|
{
|
||||||
|
int proto_num;
|
||||||
|
static struct protoent lfp;
|
||||||
|
|
||||||
|
proto_num = fgetint("/etc/protocols", " \n\t", proto);
|
||||||
|
if (proto_num > 0) {
|
||||||
|
lfp.p_name = proto;
|
||||||
|
lfp.p_proto = proto_num;
|
||||||
|
|
||||||
|
return &lfp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct protoent *getent_proto(char *proto)
|
static struct protoent *getent_proto(char *proto)
|
||||||
{
|
{
|
||||||
|
struct protoent *ent;
|
||||||
|
|
||||||
#ifdef ENABLE_STATIC
|
#ifdef ENABLE_STATIC
|
||||||
int proto_num;
|
ent = fallback_proto(proto);
|
||||||
static struct protoent lfp;
|
|
||||||
|
|
||||||
proto_num = fgetint("/etc/protocols", " \n\t", proto);
|
|
||||||
if (proto_num > 0) {
|
|
||||||
lfp.p_name = proto;
|
|
||||||
lfp.p_proto = proto_num;
|
|
||||||
|
|
||||||
return &lfp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
#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