#include <ndb_global.h>#include "common.hpp"#include <logger/Logger.hpp>#include <pwd.h>#include <Properties.hpp>#include <BaseString.hpp>Include dependency graph for common.cpp:

Go to the source code of this file.
Functions | |
| int | runas (const char *user) |
| int | insert (const char *pair, Properties &p) |
| int | insert_file (FILE *f, class Properties &p, bool break_on_empty) |
| int | insert_file (const char *filename, class Properties &p) |
Variables | |
| int | debug = 0 |
| Logger | logger |
| int insert | ( | const char * | pair, | |
| Properties & | p | |||
| ) |
Definition at line 56 of file common.cpp.
References p, split(), BaseString::split(), BaseString::trim(), and trim().
00056 { 00057 BaseString tmp(pair); 00058 00059 tmp.trim(" \t\n\r"); 00060 00061 Vector<BaseString> split; 00062 tmp.split(split, ":=", 2); 00063 00064 if(split.size() != 2) 00065 return -1; 00066 00067 p.put(split[0].trim().c_str(), split[1].trim().c_str()); 00068 00069 return 0; 00070 }
Here is the call graph for this function:

| int insert_file | ( | const char * | filename, | |
| class Properties & | p | |||
| ) |
Definition at line 93 of file common.cpp.
00093 { 00094 FILE * f = fopen(filename, "r"); 00095 int res = insert_file(f, p); 00096 if(f) fclose(f); 00097 return res; 00098 }
| int insert_file | ( | FILE * | f, | |
| class Properties & | p, | |||
| bool | break_on_empty | |||
| ) |
Definition at line 73 of file common.cpp.
Referenced by insert_file().
00073 { 00074 if(f == 0) 00075 return -1; 00076 00077 while(!feof(f)){ 00078 char buf[1024]; 00079 fgets(buf, 1024, f); 00080 BaseString tmp = buf; 00081 00082 if(tmp.length() > 0 && tmp.c_str()[0] == '#') 00083 continue; 00084 00085 if(insert(tmp.c_str(), p) != 0 && break_on_empty) 00086 break; 00087 } 00088 00089 return 0; 00090 }
Here is the caller graph for this function:

| int runas | ( | const char * | user | ) |
Definition at line 31 of file common.cpp.
References logger, and strlen().
Referenced by main(), and CPCD::Process::start().
00031 { 00032 if(user == 0 || strlen(user) == 0){ 00033 return 0; 00034 } 00035 struct passwd * pw = getpwnam(user); 00036 if(pw == 0){ 00037 logger.error("Can't find user to %s", user); 00038 return -1; 00039 } 00040 uid_t uid = pw->pw_uid; 00041 gid_t gid = pw->pw_gid; 00042 int res = setgid(gid); 00043 if(res != 0){ 00044 logger.error("Can't change group to %s(%d)", user, gid); 00045 return res; 00046 } 00047 00048 res = setuid(uid); 00049 if(res != 0){ 00050 logger.error("Can't change user to %s(%d)", user, uid); 00051 } 00052 return res; 00053 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int debug = 0 |
Definition at line 26 of file common.cpp.
Definition at line 28 of file common.cpp.
1.4.7

