mirror of
https://github.com/troglobit/finit.git
synced 2026-11-07 16:01:08 +00:00
svc_ident(): new function, returns service's unique identifier
A service is identifier using the (name,id) tuple on the form 'name:id' Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
46c028f58c
commit
59d5601f8f
1 file changed
+25
@@ -284,6 +284,31 @@ static inline const char *svc_dirtystr(svc_t *svc)
|
|||||||
return "clean";
|
return "clean";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns svc unique identifier tuple 'name:id', or just 'name',
|
||||||
|
* if that's enough to identify the service.
|
||||||
|
*/
|
||||||
|
static inline char *svc_ident(svc_t *svc, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
static char ident[sizeof(svc->name) + sizeof(svc->id) + 2];
|
||||||
|
|
||||||
|
if (!buf) {
|
||||||
|
buf = ident;
|
||||||
|
len = sizeof(ident);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!svc)
|
||||||
|
return "nil";
|
||||||
|
|
||||||
|
strlcpy(buf, svc->name, len);
|
||||||
|
if (strlen(svc->id)) {
|
||||||
|
strlcat(buf, ":", len);
|
||||||
|
strlcat(buf, svc->id, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* FINIT_SVC_H_ */
|
#endif /* FINIT_SVC_H_ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user