mirror of
https://github.com/troglobit/finit.git
synced 2026-10-06 07:43:43 +07: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:
@@ -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_ */
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user