mirror of
https://github.com/troglobit/finit.git
synced 2026-11-21 19:51:46 +00:00
Refactor, create svc_find_by_cond() from api.c callback
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
12e341fe73
commit
e589c5b269
3 files changed
+26
-14
No files matched your search
@@ -206,7 +206,6 @@ static svc_t *do_find(char *buf, size_t len)
|
|||||||
|
|
||||||
static svc_t *do_find_byc(char *buf, size_t len)
|
static svc_t *do_find_byc(char *buf, size_t len)
|
||||||
{
|
{
|
||||||
svc_t *svc, *iter = NULL;
|
|
||||||
char *input;
|
char *input;
|
||||||
|
|
||||||
input = sanitize(buf, len);
|
input = sanitize(buf, len);
|
||||||
@@ -215,17 +214,7 @@ static svc_t *do_find_byc(char *buf, size_t len)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
return svc_find_by_cond(input);
|
||||||
char cond[MAX_COND_LEN];
|
|
||||||
|
|
||||||
mkcond(svc, cond, sizeof(cond));
|
|
||||||
_d("Comparing input %s with cond %s", input, cond);
|
|
||||||
if (string_compare(cond, input))
|
|
||||||
return svc;
|
|
||||||
}
|
|
||||||
|
|
||||||
_d("None found");
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bypass_shutdown(void *);
|
static void bypass_shutdown(void *);
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ svc_t *svc_find(char *name, char *id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* svc_find_by_pid - Find an service object by its PID
|
* svc_find_by_pid - Find a service object by its PID
|
||||||
* @pid: Process ID to match
|
* @pid: Process ID to match
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
@@ -391,7 +391,29 @@ svc_t *svc_find_by_pid(pid_t pid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* svc_find_by_jobid - Find an service object by its JOB:ID
|
* svc_find_by_cond - Find a service object by its pid/foo condition
|
||||||
|
* @cond: Full "pid/foo" condition
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* A pointer to an &svc_t object, or %NULL if not found.
|
||||||
|
*/
|
||||||
|
svc_t *svc_find_by_cond(const char *cond)
|
||||||
|
{
|
||||||
|
svc_t *svc, *iter = NULL;
|
||||||
|
|
||||||
|
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
||||||
|
char buf[MAX_COND_LEN];
|
||||||
|
|
||||||
|
mkcond(svc, buf, sizeof(buf));
|
||||||
|
if (string_compare(buf, cond))
|
||||||
|
return svc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* svc_find_by_jobid - Find a service object by its JOB:ID
|
||||||
* @job: Job n:o
|
* @job: Job n:o
|
||||||
* @id: Optional instance id
|
* @id: Optional instance id
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -201,6 +201,7 @@ void svc_validate (svc_t *svc);
|
|||||||
|
|
||||||
svc_t *svc_find (char *name, char *id);
|
svc_t *svc_find (char *name, char *id);
|
||||||
svc_t *svc_find_by_pid (pid_t pid);
|
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);
|
svc_t *svc_find_by_jobid (int job, char *id);
|
||||||
svc_t *svc_find_by_tty (char *dev);
|
svc_t *svc_find_by_tty (char *dev);
|
||||||
svc_t *svc_find_by_pidfile (char *fn);
|
svc_t *svc_find_by_pidfile (char *fn);
|
||||||
|
|||||||
Reference in new issue
Block a user