Skip to content

Commit

Permalink
Make getpid() return non-zero number
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
SamLab17 authored and wkozaczuk committed Dec 8, 2020
1 parent 6759936 commit c5a0845
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion fs/procfs/procfs_vnops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <osv/prex.h>
#include <osv/sched.hh>
#include <osv/mmu.hh>
#include <osv/pid.h>

#include "fs/pseudofs/pseudofs.hh"

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

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

Expand Down
7 changes: 7 additions & 0 deletions include/osv/pid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#ifndef _OSV_PID_H_
#define _OSV_PID_H

#define OSV_PID 2

#endif
11 changes: 4 additions & 7 deletions libc/signal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <osv/clock.hh>
#include <api/setjmp.h>
#include <osv/stubbing.hh>
#include <osv/pid.h>

using namespace osv::clock::literals;

Expand Down Expand Up @@ -325,17 +326,13 @@ int kill(pid_t pid, int sig)
sig, strsignal(sig));
osv::poweroff();
} else if(!is_sig_ign(signal_actions[sig])) {
if ((pid == 0) || (pid == -1)) {
// That semantically means signalling everybody (or that, or the
// user did getpid() and got 0, all the same. So we will signal
if ((pid == OSV_PID) || (pid == 0) || (pid == -1)) {
// This semantically means signalling everybody. So we will signal
// every thread that is waiting for this.
//
// The thread does not expect the signal handler to still be delivered,
// so if we wake up some folks (usually just the one waiter), we should
// not continue processing.
//
// FIXME: Maybe it could be a good idea for our getpid() to start
// returning 1 so we can differentiate between those cases?
if (wake_up_signal_waiters(sig)) {
return 0;
}
Expand Down Expand Up @@ -482,7 +479,7 @@ void itimer::work()
} else {
_due = _no_alarm;
}
kill(0, _signum);
kill(getpid(), _signum);
if(!is_sig_ign(signal_actions[_signum])) {
_owner_thread->interrupted(true);
}
Expand Down
3 changes: 2 additions & 1 deletion libc/unistd/getppid.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <unistd.h>
#include <include/osv/pid.h>

pid_t getppid(void)
{
return 0;
return OSV_PID;
}
3 changes: 2 additions & 1 deletion runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <api/sys/prctl.h>
#include <sys/wait.h>
#include <pty.h>
#include <osv/pid.h>

#define __LC_LAST 13

Expand Down Expand Up @@ -263,7 +264,7 @@ LFS64(posix_fallocate);

int getpid()
{
return 0;
return OSV_PID;
}

// WCTDEF(alnum), WCTDEF(alpha), WCTDEF(blank), WCTDEF(cntrl),
Expand Down

0 comments on commit c5a0845

Please sign in to comment.