aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <JozanLeClerc@noemail.net>2020-11-29 17:16:20 +0000
committerJozanLeClerc <JozanLeClerc@noemail.net>2020-11-29 17:16:20 +0000
commitbada9b0ba2db5173cdb9b3bc507825a0deff2d80 (patch)
treece02ccab8398db0bbabc6fe8051ea11cb4b99541 /src
parentSeems relatively fine to me (diff)
downloadbsdsetsid-bada9b0ba2db5173cdb9b3bc507825a0deff2d80.tar.gz
bsdsetsid-bada9b0ba2db5173cdb9b3bc507825a0deff2d80.tar.bz2
bsdsetsid-bada9b0ba2db5173cdb9b3bc507825a0deff2d80.tar.xz
bsdsetsid-bada9b0ba2db5173cdb9b3bc507825a0deff2d80.tar.zst
bsdsetsid-bada9b0ba2db5173cdb9b3bc507825a0deff2d80.zip
Added man, Makefile can install
FossilOrigin-Name: 345456287af27b824c56e03b1eeebd9f73fe6562
Diffstat (limited to 'src')
-rw-r--r--src/c_args.c80
-rw-r--r--src/c_args.h61
-rw-r--r--src/c_bsdsetsid.c37
-rw-r--r--src/c_bsdsetsid.h10
-rw-r--r--src/c_fork.c22
5 files changed, 152 insertions, 58 deletions
diff --git a/src/c_args.c b/src/c_args.c
new file mode 100644
index 0000000..616b979
--- /dev/null
+++ b/src/c_args.c
@@ -0,0 +1,80 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * bsdsetsid: src/c_args.c
+ * Sun Nov 29 16:43:56 CET 2020
+ * Joe
+ *
+ * Arguments handling here.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "c_args.h"
+#include "c_bsdsetsid.h"
+
+void
+c_args
+(int argc,
+ const char* argv[],
+ bool_t* wopt)
+{
+ if (argc == 1) {
+ dprintf(STDERR_FILENO, "%s\n", C_USAGE_FMT);
+ exit(EXIT_FAILURE);
+ }
+ if (strncmp(argv[1], C_W_OPT, 3) == 0) {
+ *wopt = TRUE;
+ if (argc == 2) {
+ dprintf(STDERR_FILENO, "%s\n", C_USAGE_FMT);
+ exit(EXIT_FAILURE);
+ }
+ }
+ if (strncmp(argv[1], C_H_OPT, 3) == 0) {
+ *wopt = TRUE;
+ if (argc == 2) {
+ dprintf(STDERR_FILENO, "%s\n", C_HELP_FMT);
+ exit(EXIT_SUCCESS);
+ }
+ }
+}
diff --git a/src/c_args.h b/src/c_args.h
new file mode 100644
index 0000000..4c90c00
--- /dev/null
+++ b/src/c_args.h
@@ -0,0 +1,61 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2020 Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the organization nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * bsdsetsid: src/c_args.h
+ * Sun Nov 29 17:02:19 CET 2020
+ * Joe
+ */
+
+#ifndef __C_ARGS_H__
+#define __C_ARGS_H__
+
+#include "c_bsdsetsid.h"
+
+#define C_USAGE_FMT "usage: bsdsetsid [-hw] utility [arguments]"
+#define C_HELP_FMT \
+ "usage: bsdsetsid [-hw] utility [arguments]\n\n"\
+ "options: -h\tdisplay this help\n"\
+ " -w\twait program to exit, and use the same return"
+#define C_H_OPT "-h"
+#define C_W_OPT "-w"
+
+void c_args(int, const char*[], bool_t*);
+
+#endif /* ifndef __C_ARGS_H__ */
diff --git a/src/c_bsdsetsid.c b/src/c_bsdsetsid.c
index 7d3a76d..f8e2067 100644
--- a/src/c_bsdsetsid.c
+++ b/src/c_bsdsetsid.c
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* bsdsetsid: src/c_bsdsetsid.c
- * Thu Nov 26 22:12:37 CET 2020
+ * Sun Nov 29 16:42:26 CET 2020
* Joe
*
* This is the entrypoint of the program.
@@ -51,39 +51,10 @@
#include <string.h>
#include <unistd.h>
+#include "c_args.h"
#include "c_bsdsetsid.h"
#include "c_fork.h"
-static char
-c_args
-(int argc,
- const char* argv[],
- bool_t* wopt)
-{
- if (argc == 1) {
- dprintf(
- STDERR_FILENO,
- "%s: %s\n",
- C_PROGNAME,
- C_ERR_NOARG
- );
- return (1);
- }
- if (strncmp(argv[1], C_W_OPT, 3) == 0) {
- *wopt = TRUE;
- if (argc == 2) {
- dprintf(
- STDERR_FILENO,
- "%s: %s\n",
- C_PROGNAME,
- C_ERR_NOARG
- );
- return (1);
- }
- }
- return (0);
-}
-
int
main
(int argc,
@@ -93,9 +64,7 @@ main
bool_t wopt;
wopt = FALSE;
- if (c_args(argc, argv, &wopt) != 0) {
- return (EXIT_FAILURE);
- }
+ c_args(argc, argv, &wopt);
c_fork(argv, envp, wopt);
return (EXIT_SUCCESS);
}
diff --git a/src/c_bsdsetsid.h b/src/c_bsdsetsid.h
index d7f7724..740bd7d 100644
--- a/src/c_bsdsetsid.h
+++ b/src/c_bsdsetsid.h
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* bsdsetsid: src/c_bsdsetsid.h
- * Fri Nov 27 01:48:28 CET 2020
+ * Sun Nov 29 17:02:13 CET 2020
* Joe
*
* This is the entrypoint of the program.
@@ -47,6 +47,8 @@
#ifndef __C_BSDSETSID_H__
#define __C_BSDSETSID_H__
+#define C_PROGNAME "bsdsetsid"
+
typedef char bool_t;
typedef void* ptr_t;
@@ -55,8 +57,4 @@ enum bool_e {
TRUE
};
-#define C_PROGNAME "bsdsetsid"
-#define C_ERR_NOARG "no program specified"
-#define C_W_OPT "-w"
-
-#endif
+#endif /* ifndef __C_BSDSETSID_H__ */
diff --git a/src/c_fork.c b/src/c_fork.c
index ee754ba..61a3016 100644
--- a/src/c_fork.c
+++ b/src/c_fork.c
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* bsdsetsid: src/c_fork.c
- * Fri Nov 27 01:48:00 CET 2020
+ * Sun Nov 29 15:26:58 CET 2020
* Joe
*
* The program's main fork(2).
@@ -121,22 +121,13 @@ c_fork_child
u.pid = setsid();
if (u.pid == -1) {
- dprintf(
- STDERR_FILENO,
- "%s: setsid: %s\n",
- C_PROGNAME,
- strerror(errno)
- );
+ dprintf(STDERR_FILENO, "%s: setsid: %s\n", C_PROGNAME, strerror(errno));
exit(EXIT_FAILURE);
}
path = mem;
u.ret = c_get_path(argv[1 + wopt], envp, path);
if (u.ret == 1) {
- dprintf(
- STDERR_FILENO,
- "%s: PATH not set\n",
- C_PROGNAME
- );
+ dprintf(STDERR_FILENO, "%s: PATH not set\n", C_PROGNAME);
exit(EXIT_FAILURE);
}
else if (u.ret == 2) {
@@ -191,12 +182,7 @@ c_fork_parent
static void
c_fork_error(void)
{
- dprintf(
- STDERR_FILENO,
- "%s: fork: %s\n",
- C_PROGNAME,
- strerror(errno)
- );
+ dprintf(STDERR_FILENO, "%s: fork: %s\n", C_PROGNAME, strerror(errno));
exit(EXIT_FAILURE);
}