Minor refactor, break out new fn svc_find_by_str()

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-02-28 00:49:55 +01:00
parent 9cb6a54493
commit ed383eaaa6
2 changed files with 28 additions and 9 deletions
+27 -9
View File
@@ -371,6 +371,32 @@ svc_t *svc_find(char *name, char *id)
return NULL;
}
/**
* svc_find_by_str - Find a service object by name:id
* @str: name[:id]
*
* Like svc_find() but takes 'name[:id]' argument
*
* Returns:
* A pointer to an &svc_t object, or %NULL if not found.
*/
svc_t *svc_find_by_str(const char *str)
{
char *name, *id;
if (!str)
return NULL;
name = strdupa(str);
id = strchr(name, ':');
if (id)
*id++ = 0;
else
id = "";
return svc_find(name, id);
}
/**
* svc_find_by_pid - Find a service object by its PID
* @pid: Process ID to match
@@ -644,17 +670,9 @@ int svc_conflicts(svc_t *svc)
nm = strtok(ptr, ",");
while (nm) {
char *name, *id;
svc_t *s;
name = strdupa(nm);
id = strchr(name, ':');
if (id)
id++ = 0;
else
id = "";
s = svc_find(name, id);
s = svc_find_by_str(nm);
if (s) {
if (s->state >= SVC_STOPPING_STATE)
rc = 1;
+1
View File
@@ -210,6 +210,7 @@ int svc_del (svc_t *svc);
void svc_validate (svc_t *svc);
svc_t *svc_find (char *name, char *id);
svc_t *svc_find_by_str (const char *str);
svc_t *svc_find_by_pid (pid_t pid);
svc_t *svc_find_by_cond (const char *cond);
svc_t *svc_find_by_jobid (int job, char *id);