sm

sysmgr implemented in C
git clone git://git.ckyln.com/sm
Log | Files | Refs | README | LICENSE

sysmgr-depends.c (1633B)


      1 /* sysmgr-depends -- Wait until given services are up and running
      2  *
      3  * Copyright (C) 2020 Cem Keylan <cem@ckyln.com>
      4  *
      5  * This program is free software: you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation, either version 3 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  * GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
     17  */
     18 #include <stdio.h>
     19 #include <stdlib.h>
     20 #include <unistd.h>
     21 #include <string.h>
     22 
     23 #include "util.h"
     24 #include "config.h"
     25 static char *argv0;
     26 
     27 void
     28 usage(void)
     29 {
     30 	printf("usage: %s [service...]\n\nsysmgr-%s\n", argv0, VERSION);
     31 	exit(0);
     32 }
     33 
     34 int
     35 main (int argc, char *argv[])
     36 {
     37 	/* Variables used by other functions but not in this file itself */
     38 	(void)(sysdir_default);
     39 	(void)(rundir_default);
     40 
     41 	int i;
     42 	argv0 = argv[0];
     43 	if (argc < 2 || strncmp(argv[1], "-", 1) == 0)
     44 		usage();
     45 
     46 	/* Make a check that the services are actually valid. */
     47 	for (i=1; i < argc; i++) {
     48 		struct service sv;
     49 		sv_init(&sv, argv[i]);
     50 		if (access(sv.svfile, R_OK) < 0)
     51 			die("service file for '%s' could not be found", argv[i]);
     52 	}
     53 
     54 	for (i=1; i < argc; i++) {
     55 		struct service sv;
     56 		sv_init(&sv, argv[i]);
     57 		while(1) {
     58 			if (sv_check(&sv, 1) == 0)
     59 				break;
     60 			sleep(1);
     61 		}
     62 	}
     63 }