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:
Joachim Wiberg
2021-02-11 07:53:51 +01:00
parent 46c028f58c
commit 59d5601f8f
+25
View File
@@ -284,6 +284,31 @@ static inline const char *svc_dirtystr(svc_t *svc)
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_ */
/**