Make job IDs unpredictable v1 PROPOSED

Drew DeVault: 1
 Make job IDs unpredictable

 1 files changed, 6 insertions(+), 0 deletions(-)
View this thread in the archives
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/mrsh-dev/%3C20190607202437.30044-1-sir%40cmpwn.com%3E/mbox | git am -3
Learn more about email & git

[PATCH] Make job IDs unpredictable Export this patch

---
 shell/job.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/shell/job.c b/shell/job.c
index 8f1c79b..9ab0927 100644
--- a/shell/job.c
+++ b/shell/job.c
@@ -8,6 +8,7 @@
 #include <string.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <time.h>
 #include <unistd.h>
 #include "shell/job.h"
 #include "shell/process.h"
@@ -91,6 +92,11 @@ struct mrsh_job *job_create(struct mrsh_state *state, pid_t pgid) {
 		}
 	}
 
+	/* Makes job IDs unpredictable so you cannot rely on them (the allocation of
+	 * job IDs is not specified by POSIX) */
+	id *= 10;
+	id += time(NULL) % 10;
+
 	struct mrsh_job *job = calloc(1, sizeof(struct mrsh_job));
 	job->state = state;
 	job->pgid = pgid;
-- 
2.21.0