Author: Dharanendiran <dharanendiran@timesys.com>
Date: Mon, 24 Jan 2022 20:51:33 +0530

Error log:
../../source3/printing/queue_process.c:24:19: fatal error: spawn.h: No such file or directory
 #include <spawn.h>

---
 source3/printing/queue_process.c | 20 ++++++++++++++++++++
 source3/rpc_client/local_np.c    | 19 +++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/source3/printing/queue_process.c b/source3/printing/queue_process.c
index 6613e8f..5cd5e4f 100644
--- a/source3/printing/queue_process.c
+++ b/source3/printing/queue_process.c
@@ -21,7 +21,9 @@
 */
 
 #include "includes.h"
+#if !defined (__UCLIBC__)
 #include <spawn.h>
+#endif
 #include "smbd/globals.h"
 #include "include/messages.h"
 #include "lib/util/util_process.h"
@@ -387,14 +389,31 @@ pid_t start_background_queue(struct tevent_context *ev,
 		goto nomem;
 	}
 
+#if !defined (__UCLIBC__)
 	ret = posix_spawn(&pid, argv[0], NULL, NULL, argv, environ);
 	if (ret == -1) {
 		goto fail;
 	}
+#else
+	switch (fork()) {
+	case -1:
+		return -1;
+	case 0:
+		execve(argv[0], argv, environ);
+		/* execve() returns only on error */
+		fprintf(stderr, "execve failed due to %s\n", strerror(errno));
+		/* not usually reached */
+		exit(EXIT_FAILURE);
+	default: /* parent */
+		wait(&ret);
+	}
+	return 0;
+#endif
 	TALLOC_FREE(argv);
 
 	close(ready_fds[1]);
 
+#if !defined (__UCLIBC__)
 	nread = sys_read(ready_fds[0], &pid, sizeof(pid));
 	close(ready_fds[0]);
 	if (nread != sizeof(pid)) {
@@ -403,6 +422,7 @@ pid_t start_background_queue(struct tevent_context *ev,
 
 	return pid;
 
+#endif
 nomem:
 	errno = ENOMEM;
 fail:
diff --git a/source3/rpc_client/local_np.c b/source3/rpc_client/local_np.c
index 791ded9..263ae53 100644
--- a/source3/rpc_client/local_np.c
+++ b/source3/rpc_client/local_np.c
@@ -16,7 +16,9 @@
  */
 
 #include "source3/include/includes.h"
+#if !defined (__UCLIBC__)
 #include <spawn.h>
+#endif
 #include "local_np.h"
 #include "lib/async_req/async_sock.h"
 #include "librpc/gen_ndr/ndr_named_pipe_auth.h"
@@ -381,6 +383,7 @@ static struct tevent_req *start_rpc_host_send(
 	}
 
 	become_root();
+#if !defined (__UCLIBC__)
 	ret = posix_spawn(&pid, argv[0], NULL, NULL, argv, environ);
 	unbecome_root();
 	if (ret != 0) {
@@ -388,6 +391,22 @@ static struct tevent_req *start_rpc_host_send(
 		goto fail;
 	}
 
+#else
+	switch (fork()) {
+	case -1:
+		return -1;
+	case 0:
+		execve(argv[0], argv, environ);
+		/* execve() returns only on error */
+		fprintf(stderr, "execve failed due to %s\n", strerror(errno));
+		/* not usually reached */
+		exit(EXIT_FAILURE);
+	default: /* parent */
+		wait(&ret);
+	}
+	return 0;
+#endif
+
 	state->ready_fd = ready_fds[0];
 	ready_fds[0] = -1;
 	tevent_req_set_cleanup_fn(req, start_rpc_host_cleanup);
-- 
2.25.1

