home | blog | art | now | git gpg | email | rss

splashdown

Minimal bootsplash program
git clone https://pollux.codes/git/splashdown.git
Log | Files | Refs | README | LICENSE

splashdown-openrc-plugin.c (2225B)


      1 
      2 /*
      3  * splashdown - minimal bootsplash program
      4  * Copyright (C) 2026 Pollux <pollux@pollux.codes>
      5  * 
      6  * This program is free software: you can redistribute it and/or modify
      7  * it under the terms of the GNU General Public License as published by
      8  * the Free Software Foundation, either version 3 of the License, or
      9  * (at your option) any later version.
     10  * 
     11  * This program is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  * GNU General Public License for more details.
     15  * 
     16  * You should have received a copy of the GNU General Public License
     17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
     18  */
     19 
     20 #include <errno.h>
     21 #include <rc.h>
     22 #include <stdarg.h>
     23 #include <stdint.h>
     24 #include <stdlib.h>
     25 #include <string.h>
     26 #include <sys/wait.h>
     27 #include <unistd.h>
     28 
     29 #define LENGTH(X) (sizeof (X) / sizeof (X)[0])
     30 
     31 void            die(const char *fmt, ...);
     32 int             run_splashdown(char *message, char *service);
     33 
     34 #include "config.h"
     35 
     36 void
     37 die(const char *fmt, ...) {
     38 	va_list         ap;
     39 	int             saved_errno;
     40 
     41 	saved_errno = errno;
     42 
     43 	va_start(ap, fmt);
     44 	vfprintf(stderr, fmt, ap);
     45 	va_end(ap);
     46 
     47 	if(fmt[0] && fmt[strlen(fmt) - 1] == ':')
     48 		fprintf(stderr, " %s", strerror(saved_errno));
     49 	fputc('\n', stderr);
     50 	exit(1);
     51 }
     52 
     53 int
     54 run_splashdown(char *message, char *service) {
     55 
     56 	char            cmd[128];
     57 
     58 	cmd[0] = '\0';
     59 
     60 	strcpy(cmd, "splashdown '");
     61 	strcat(cmd, message);
     62 	strcat(cmd, service);
     63 	strcat(cmd, "...'");
     64 
     65 	int             rv = system(cmd);
     66 
     67 	return rv;
     68 }
     69 
     70 int
     71 rc_plugin_hook(RC_HOOK hook, const char *name) {
     72 
     73 	int             rv = 0;
     74 
     75 	char            name_cpy[256];
     76 
     77 	strcpy(name_cpy, name);
     78 
     79 	char           *runlevel = rc_runlevel_get();
     80 
     81 	for(uint32_t i = 0; i < LENGTH(openrc_exclude); i++) {
     82 		if(!strcmp(name_cpy, openrc_exclude[i])) {
     83 			goto end;
     84 		}
     85 	}
     86 
     87 	switch (hook) {
     88 	case RC_HOOK_SERVICE_START_NOW:
     89 		if(run_splashdown("Starting ", name_cpy)) {
     90 			rv = 1;
     91 		}
     92 		break;
     93 	case RC_HOOK_SERVICE_STOP_NOW:
     94 		if(run_splashdown("Stopping ", name_cpy)) {
     95 			rv = 1;
     96 		}
     97 		break;
     98 	default:
     99 		break;
    100 	}
    101 
    102 	end:
    103 
    104 	free(runlevel);
    105 	return rv;
    106 }