Skip to content

Commit c5a0845

Browse files
SamLab17wkozaczuk
authored andcommitted
Make getpid() return non-zero number
getpid() no longer returns 0 as the pid of the kernel/application, and instead uses the constant defined in include/osv/pid.h. Signed-off-by: Samuel Laberge <samlaberge817@gmail.com> Message-Id: <20201206195248.53500-2-samlaberge817@gmail.com>
1 parent 6759936 commit c5a0845

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

fs/procfs/procfs_vnops.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <osv/prex.h>
1313
#include <osv/sched.hh>
1414
#include <osv/mmu.hh>
15+
#include <osv/pid.h>
1516

1617
#include "fs/pseudofs/pseudofs.hh"
1718

@@ -177,7 +178,7 @@ procfs_mount(mount* mp, const char *dev, int flags, const void* data)
177178

178179
auto* root = new pseudo_dir_node(vp->v_ino);
179180
root->add("self", self);
180-
root->add("0", self); // our standard pid
181+
root->add(std::to_string(OSV_PID), self); // our standard pid
181182
root->add("mounts", inode_count++, procfs_mounts);
182183
root->add("sys", sys);
183184

include/osv/pid.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
#ifndef _OSV_PID_H_
3+
#define _OSV_PID_H
4+
5+
#define OSV_PID 2
6+
7+
#endif

libc/signal.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <osv/clock.hh>
1919
#include <api/setjmp.h>
2020
#include <osv/stubbing.hh>
21+
#include <osv/pid.h>
2122

2223
using namespace osv::clock::literals;
2324

@@ -325,17 +326,13 @@ int kill(pid_t pid, int sig)
325326
sig, strsignal(sig));
326327
osv::poweroff();
327328
} else if(!is_sig_ign(signal_actions[sig])) {
328-
if ((pid == 0) || (pid == -1)) {
329-
// That semantically means signalling everybody (or that, or the
330-
// user did getpid() and got 0, all the same. So we will signal
329+
if ((pid == OSV_PID) || (pid == 0) || (pid == -1)) {
330+
// This semantically means signalling everybody. So we will signal
331331
// every thread that is waiting for this.
332332
//
333333
// The thread does not expect the signal handler to still be delivered,
334334
// so if we wake up some folks (usually just the one waiter), we should
335335
// not continue processing.
336-
//
337-
// FIXME: Maybe it could be a good idea for our getpid() to start
338-
// returning 1 so we can differentiate between those cases?
339336
if (wake_up_signal_waiters(sig)) {
340337
return 0;
341338
}
@@ -482,7 +479,7 @@ void itimer::work()
482479
} else {
483480
_due = _no_alarm;
484481
}
485-
kill(0, _signum);
482+
kill(getpid(), _signum);
486483
if(!is_sig_ign(signal_actions[_signum])) {
487484
_owner_thread->interrupted(true);
488485
}

libc/unistd/getppid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <unistd.h>
2+
#include <include/osv/pid.h>
23

34
pid_t getppid(void)
45
{
5-
return 0;
6+
return OSV_PID;
67
}

runtime.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include <api/sys/prctl.h>
6161
#include <sys/wait.h>
6262
#include <pty.h>
63+
#include <osv/pid.h>
6364

6465
#define __LC_LAST 13
6566

@@ -263,7 +264,7 @@ LFS64(posix_fallocate);
263264

264265
int getpid()
265266
{
266-
return 0;
267+
return OSV_PID;
267268
}
268269

269270
// WCTDEF(alnum), WCTDEF(alpha), WCTDEF(blank), WCTDEF(cntrl),

0 commit comments

Comments
 (0)