-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinding.cc
More file actions
33 lines (27 loc) · 833 Bytes
/
binding.cc
File metadata and controls
33 lines (27 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "credentials.hh"
#include <nan.h>
NAN_METHOD(FromFd) {
auto fd = Nan::To<int>(info[0]).FromJust();
auto ret = Nan::New<v8::Object>();
info.GetReturnValue().Set(ret);
#define SET_RETVAL(key, value) Nan::Set(ret, Nan::New(key).ToLocalChecked(), Nan::New(value))
Credentials creds;
if (!creds.Init(fd)) {
SET_RETVAL("errno", errno);
return;
}
SET_RETVAL("pid", creds.GetPid());
SET_RETVAL("uid", creds.GetUid());
SET_RETVAL("gid", creds.GetGid());
#ifdef CREDENTIALS_HAS_PPID
SET_RETVAL("ppid", creds.GetPpid());
#endif
#ifdef CREDENTIALS_HAS_PGID
SET_RETVAL("pgid", creds.GetPgid());
#endif
}
NAN_MODULE_INIT(Init) {
Nan::Set(target, Nan::New("fromFd").ToLocalChecked(),
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(FromFd)).ToLocalChecked());
}
NODE_MODULE(NativeExtension, Init)