Skip to content

Instantly share code, notes, and snippets.

@bhaskarvk
Last active October 25, 2015 01:45
Show Gist options
  • Save bhaskarvk/6a15083ab9a7997df0a2 to your computer and use it in GitHub Desktop.
Save bhaskarvk/6a15083ab9a7997df0a2 to your computer and use it in GitHub Desktop.
Shiny Server patch for Solaris
diff --git a/src/launcher.cc b/src/launcher.cc
index d8d04b6..835b149 100644
--- a/src/launcher.cc
+++ b/src/launcher.cc
@@ -73,7 +73,11 @@ int main(int argc, char **argv) {
int findBaseDir(std::string* shinyServerPath) {
char execPath[MAXPATHLEN + 1];
+#ifdef __sun
+ int cn = snprintf(execPath, MAXPATHLEN + 1, "/proc/%d/path/a.out", getpid());
+#else
int cn = snprintf(execPath, MAXPATHLEN + 1, "/proc/%d/exe", getpid());
+#endif
if (cn < 0 || cn > MAXPATHLEN) {
// Not expected
return 2;
@@ -82,14 +86,22 @@ int findBaseDir(std::string* shinyServerPath) {
struct stat execStat;
if (lstat(execPath, &execStat)) {
if (errno == ENOENT)
+#ifdef __sun
+ fprintf(stderr, "/proc/%d/path/a.out doesn't exist--got Solaris?\n", getpid());
+#else
fprintf(stderr, "/proc/%d/exe doesn't exist--got Linux?\n", getpid());
+#endif
else
fprintf(stderr, "Fatal error calling lstat: %d\n", errno);
return 1;
}
if (!S_ISLNK(execStat.st_mode)) {
+#ifdef __sun
+ fprintf(stderr, "/proc/%d/path/a.out was not a symlink\n", getpid());
+#else
fprintf(stderr, "/proc/%d/exe was not a symlink\n", getpid());
+#endif
return 1;
}
diff --git a/src/posix.cc b/src/posix.cc
index 83fee64..b08932e 100644
--- a/src/posix.cc
+++ b/src/posix.cc
@@ -23,6 +23,57 @@
using namespace node;
using namespace v8;
+#ifdef __sun
+// Solaris does not have getgrouplist
+#include <string.h>
+int
+getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt)
+{
+ const struct group *grp;
+ int i, maxgroups, ngroups, ret;
+
+ ret = 0;
+ ngroups = 0;
+ maxgroups = *grpcnt;
+ /*
+ * When installing primary group, duplicate it;
+ * the first element of groups is the effective gid
+ * and will be overwritten when a setgid file is executed.
+ */
+ groups ? groups[ngroups++] = agroup : ngroups++;
+ if (maxgroups > 1)
+ groups ? groups[ngroups++] = agroup : ngroups++;
+ /*
+ * Scan the group file to find additional groups.
+ */
+ setgrent();
+ while ((grp = getgrent()) != NULL) {
+ if (groups) {
+ for (i = 0; i < ngroups; i++) {
+ if (grp->gr_gid == groups[i])
+ goto skip;
+ }
+ }
+ for (i = 0; grp->gr_mem[i]; i++) {
+ if (!strcmp(grp->gr_mem[i], uname)) {
+ if (ngroups >= maxgroups) {
+ ret = -1;
+ break;
+ }
+ groups ? groups[ngroups++] = grp->gr_gid : ngroups++;
+ break;
+ }
+ }
+skip:
+ ;
+ }
+ endgrent();
+ *grpcnt = ngroups;
+ return (ret);
+}
+#endif
+
+
Handle<Value> GetPwNam(const Arguments& args) {
HandleScope scope;
@@ -121,7 +172,7 @@ Handle<Value> GetGroupList(const Arguments& args) {
bufsize = 16384;
char buf[bufsize];
-#ifdef __linux__
+#if defined( __linux__) || defined(__sun)
typedef gid_t result_t;
#else
typedef int result_t;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment