diff options
Diffstat (limited to 'initd')
-rw-r--r-- | initd/init.h | 96 | ||||
-rw-r--r-- | initd/main.c | 17 | ||||
-rw-r--r-- | initd/mksock.c | 17 | ||||
-rw-r--r-- | initd/runlst.c | 17 | ||||
-rw-r--r-- | initd/setup_tty.c | 17 | ||||
-rw-r--r-- | initd/shutdown.c | 17 | ||||
-rw-r--r-- | initd/status.c | 17 | ||||
-rw-r--r-- | initd/svclist.c | 17 |
8 files changed, 215 insertions, 0 deletions
diff --git a/initd/init.h b/initd/init.h index 0bfed6c..dee0b00 100644 --- a/initd/init.h +++ b/initd/init.h @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ #ifndef INIT_H #define INIT_H @@ -14,22 +31,101 @@ enum { STATUS_WAIT, }; +/********** runlst.c **********/ + +/* + Plow through an array of strings and execute each one, i.e. do + a fork() and exec(). + + In the parent process, wait() until the child is done before + continuing through the list. + + If ctty is not NULL, open it and redirect all I/O of the child + process to that file. + + If everyhing works, the function returns EXIT_SUCCESS. If one child + does not exit with EXIT_SUCCESS, processing of the list is aborted + and the function returns the exit status of the failed process. +*/ int runlst_wait(char **exec, size_t num, const char *ctty); +/* + Does basically the same as runlst_wait, but asynchronously. + + A child process is created that calls runlst_wait exits with the + result of runlst_wait. In the parent process, the function returns + immediately with the PID of the child process. + + Alternatively, if num is 1, the child process directly exec()s the + given command. +*/ pid_t runlst(char **exec, size_t num, const char *ctty); +/********** setup_tty.c **********/ + +/* + Initial tty setup for init. Makes /dev/console our controlling tty and + reroutes all output there. Closes stdin because we presumably won't + need it anymore. + + Returns 0 on success, -1 on failure. The function takes care of + printing error messages on failure. +*/ int setup_tty(void); +/********** status.c **********/ + +/* + Print a status message. Type is either STATUS_OK, STATUS_FAIL or + STATUS_WAIT. + + A new-line is appended to the mssage, UNLESS type is STATUS_WAIT. + + If update is true, print a carriage return first to overwrite the + current line (e.g. after a STATUS_WAIT message). +*/ void print_status(const char *msg, int type, bool update); +/********** mksock.c **********/ + +/* + Create a UNIX socket that programs can use to pass messages to init. + + Returns the socked fd or -1 on failure. The function takes care of + printing error messages on failure. + + The socket has the CLOEXEC flag set. +*/ int mksock(void); +/********** shutdown.c **********/ + +/* + Kindly tell all processes to go kill themselves, then send + a SIGKILL if they don't and perform system shutdown. + + The argument is passed directly to the reboot() syscall. +*/ NORETURN void do_shutdown(int type); +/********** svclist.c **********/ + +/* + Returns true if the list of running services contains + single shot processes. +*/ bool svclist_have_singleshot(void); +/* Add a service to the list of running services */ void svclist_add(service_t *svc); +/* + Remove a service, identifierd by PID, from the list of + running services. + + Returns the service identified by the PID or NULL if there + is no such service. +*/ service_t *svclist_remove(pid_t pid); #endif /* INIT_H */ diff --git a/initd/main.c b/initd/main.c index 211188e..be9fc0d 100644 --- a/initd/main.c +++ b/initd/main.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <sys/types.h> #include <sys/wait.h> #include <sys/socket.h> diff --git a/initd/mksock.c b/initd/mksock.c index ab26e51..6a9cab0 100644 --- a/initd/mksock.c +++ b/initd/mksock.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <sys/types.h> #include <sys/socket.h> #include <sys/stat.h> diff --git a/initd/runlst.c b/initd/runlst.c index cf75126..908ec15 100644 --- a/initd/runlst.c +++ b/initd/runlst.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <sys/wait.h> #include <signal.h> #include <unistd.h> diff --git a/initd/setup_tty.c b/initd/setup_tty.c index cec663b..807b69d 100644 --- a/initd/setup_tty.c +++ b/initd/setup_tty.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <unistd.h> #include <fcntl.h> #include <stdio.h> diff --git a/initd/shutdown.c b/initd/shutdown.c index 45af1c2..1ee68c2 100644 --- a/initd/shutdown.c +++ b/initd/shutdown.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <stdlib.h> #include <unistd.h> #include <string.h> diff --git a/initd/status.c b/initd/status.c index 280670b..67b049b 100644 --- a/initd/status.c +++ b/initd/status.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <stdio.h> #include "init.h" diff --git a/initd/svclist.c b/initd/svclist.c index 590091e..4ed897f 100644 --- a/initd/svclist.c +++ b/initd/svclist.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ #include "init.h" static service_t *running = NULL; /* currently supervised services */ |