int start_server(int port_number, const char* dir_name, int period)
{
pthread_t tid; /* Passed to pthread_create */
struct thread_arg* targ; /* Used to pass arguments to threads */
pthread_attr_t tattr; /* Specifies that thread should be detached */
fd_set master; /* Keep track of all connections / pipes to multiplex */
fd_set read_fds; /* Copy of master for select to populate */
int fdmax; /* Highest numbered file descriptor */
int i; /* Used to index the master fd list */
int listener; /* Listening socket of the server */
int newfd; /* New connection socket fd */
struct sockaddr_in local_addr; /* Local connection info */
struct sockaddr_in remote_addr; /* Remote connection info */
socklen_t addr_len; /* Address length */
int pipe_buff[1]; /* Get sockets into here */
pipe_buff[0] = 0;
// Init signal mask
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = SIG_IGN;
// Start each thread in detached mode, since we don't care about
// their return values
pthread_attr_init(&tattr);
pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
// Initialize the memory pool to store the direntries
direntry_pool = init_mempool(sizeof(struct direntry), 512);
// Set done to 0
done = 0;
// Initialize the clients linked list
clients = (struct clientlist*)malloc(sizeof(struct clientlist));
clients->head = NULL;
clients->tail = NULL;
clients->count = 0;
// Copy into global init_dir
strcpy(init_dir, dir_name);
gperiod = period;
// Initialize pipe
if (pipe(remove_client_pipes) < 0) {
syslog(LOG_ERR, "Cannot create IPC in server.");
exit(1);
}
// Get full path of the directory
if (realpath(dir_name, full_path) == NULL) {
syslog(LOG_ERR, "Cannot resolve full path.");
exit(1);
}
#ifdef DAEMONIZE
create_daemon("dirapp");
#endif
#ifndef DAEMONIZE
openlog("dirapp", LOG_CONS, LOG_DAEMON);
#endif
// Make sure SIGPIPE is blocked
if (sigaction(SIGPIPE, &sa, NULL) < 0) {
syslog(LOG_WARNING, "SIGPIPE error");
}
// Signals for the signal thread to handle
sigemptyset(&mask);
sigaddset(&mask, SIGHUP);
sigaddset(&mask, SIGTERM);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGALRM);
// Set the mask
if (pthread_sigmask(SIG_BLOCK, &mask, NULL) != 0)
syslog(LOG_WARNING, "pthread_sigmask failed");
// Initialize file descriptor lists
FD_ZERO(&master);
FD_ZERO(&read_fds);
// Setup local connection info
memset(&local_addr, 0, sizeof(local_addr));
local_addr.sin_family = AF_INET;
local_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
local_addr.sin_port = htons(port_number);
// Create listener socket
listener = socket(AF_INET, SOCK_STREAM, 0);
// Try to bind
if (bind(listener, (struct sockaddr*)&local_addr, sizeof(local_addr))) {
syslog(LOG_ERR, "Cannot bind socket to address");
exit(1);
}
// Now listen!
if (listen(listener, MAX_CLIENTS) < 0) {
//.........这里部分代码省略.........
开发者ID:cmoresid,项目名称:dirapp,代码行数:101,代码来源:server.c
示例2: proxenet_add_new_plugins
/**
* Plugin name structure *MUST* be `PLUGIN_DIR/[<priority>]<name>.<ext>`
* <priority> is an int in [1, 9]. If <priority> is found as the first char of the
* file name, it will be applied to the plugin. If no priority is specify, a default
* priority will be applied.
*
* If a file does not match this pattern, it will be discarded
*
* @param plugin_path is the path to look for plugins
* @param plugin_name is the name of the plugin to add. If NULL, this function will try
* to *all* the files in the directory.
* @return the number of added plugins on success, -1 on error
*/
int proxenet_add_new_plugins(char* plugin_path, char* plugin_name)
{
struct dirent *dir_ptr=NULL;
DIR *dir = NULL;
char* name = NULL;
short type=-1, priority;
int d_name_len;
bool add_all = (plugin_name==NULL)?true:false;
unsigned int nb_plugin_added = 0;
#ifdef DEBUG
if (add_all)
xlog(LOG_DEBUG, "Trying to add all files in '%s'\n", plugin_path);
else
xlog(LOG_DEBUG, "Trying to add '%s/%s'\n", plugin_path, plugin_name);
#endif
dir = opendir(plugin_path);
if (dir == NULL) {
xlog(LOG_ERROR, "Failed to open '%s': %s\n", plugin_path, strerror(errno));
return -1;
}
while ((dir_ptr=readdir(dir))) {
if (strcmp(dir_ptr->d_name,".")==0)
continue;
if (strcmp(dir_ptr->d_name,"..")==0)
continue;
/* if add one plugin, loop until the right name */
if (!add_all && strcmp(dir_ptr->d_name, plugin_name)!=0)
continue;
if (dir_ptr->d_type == DT_LNK){
/* if entry is a symlink, ensure it's pointing to a file in plugins_path */
ssize_t l = -1;
char fullpath[PATH_MAX] = {0, };
char realpath_buf[PATH_MAX] = {0, };
l = snprintf(fullpath, PATH_MAX, "%s/%s", plugin_path, dir_ptr->d_name);
if(l == -1){
xlog(LOG_ERROR, "snprintf() failed on '%s'\n",
dir_ptr->d_name ,
errno,
strerror(errno));
continue;
}
if(!realpath(fullpath, realpath_buf)){
xlog(LOG_ERROR, "realpath failed on '%s': %d - %s\n",
fullpath,
errno,
strerror(errno));
continue;
}
l = strlen(cfg->plugins_path);
if( strncmp(realpath_buf, cfg->plugins_path, l) != 0 )
continue;
} else {
/* if not a symlink nor regular file, continue */
if (dir_ptr->d_type != DT_REG)
continue;
}
/* if first char is valid integer, this will be the plugin priority */
if (atoi(&(dir_ptr->d_name[0])) > 0)
priority = (unsigned short)atoi(&(dir_ptr->d_name[0]));
else
priority = (unsigned short) CFG_DEFAULT_PLUGIN_PRIORITY;
/* plugin name */
d_name_len = strlen(dir_ptr->d_name);
if (d_name_len > 510)
continue;
name = dir_ptr->d_name;
/* plugin type */
type = proxenet_get_plugin_type(name);
if (type < 0)
continue;
if ( proxenet_is_plugin_loaded(name) ){
xlog(LOG_WARNING, "A plugin named '%s' is already loaded\n", name);
//.........这里部分代码省略.........
int
main (int argc, char *argv[]) {
int portable = 0;
#if STATICLINK
int staticlink = 1;
#else
int staticlink = 0;
#endif
#if PORTABLE
portable = 1;
if (!realpath (argv[0], dbinstalldir)) {
strcpy (dbinstalldir, argv[0]);
}
char *e = strrchr (dbinstalldir, '/');
if (e) {
*e = 0;
}
else {
fprintf (stderr, "couldn't determine install folder from path %s\n", argv[0]);
exit (-1);
}
#else
if (!realpath (argv[0], dbinstalldir)) {
strcpy (dbinstalldir, argv[0]);
}
char *e = strrchr (dbinstalldir, '/');
if (e) {
*e = 0;
struct stat st;
char checkpath[PATH_MAX];
snprintf (checkpath, sizeof (checkpath), "%s/.ddb_portable", dbinstalldir);
if (!stat (checkpath, &st)) {
if (S_ISREG (st.st_mode)) {
portable = 1;
}
}
}
if (!portable) {
strcpy (dbinstalldir, PREFIX);
}
#endif
#ifdef __GLIBC__
signal (SIGSEGV, sigsegv_handler);
#endif
setlocale (LC_ALL, "");
setlocale (LC_NUMERIC, "C");
#ifdef ENABLE_NLS
// fprintf (stderr, "enabling gettext support: package=" PACKAGE ", dir=" LOCALEDIR "...\n");
if (portable) {
char localedir[PATH_MAX];
snprintf (localedir, sizeof (localedir), "%s/locale", dbinstalldir);
bindtextdomain (PACKAGE, localedir);
}
else {
bindtextdomain (PACKAGE, LOCALEDIR);
}
bind_textdomain_codeset (PACKAGE, "UTF-8");
textdomain (PACKAGE);
#endif
fprintf (stderr, "starting deadbeef " VERSION "%s%s\n", staticlink ? " [static]" : "", portable ? " [portable]" : "");
srand (time (NULL));
#ifdef __linux__
prctl (PR_SET_NAME, "deadbeef-main", 0, 0, 0, 0);
#endif
#if PORTABLE_FULL
if (snprintf (confdir, sizeof (confdir), "%s/config", dbinstalldir) > sizeof (confdir)) {
fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
return -1;
}
strcpy (dbconfdir, confdir);
#else
char *homedir = getenv ("HOME");
if (!homedir) {
fprintf (stderr, "unable to find home directory. stopping.\n");
return -1;
}
char *xdg_conf_dir = getenv ("XDG_CONFIG_HOME");
if (xdg_conf_dir) {
if (snprintf (confdir, sizeof (confdir), "%s", xdg_conf_dir) > sizeof (confdir)) {
fprintf (stderr, "fatal: XDG_CONFIG_HOME value is too long: %s\n", xdg_conf_dir);
return -1;
}
}
else {
if (snprintf (confdir, sizeof (confdir), "%s/.config", homedir) > sizeof (confdir)) {
fprintf (stderr, "fatal: HOME value is too long: %s\n", homedir);
return -1;
}
}
if (snprintf (dbconfdir, sizeof (dbconfdir), "%s/deadbeef", confdir) > sizeof (dbconfdir)) {
fprintf (stderr, "fatal: out of memory while configuring\n");
return -1;
}
mkdir (confdir, 0755);
#endif
//.........这里部分代码省略.........
开发者ID:Gardenya,项目名称:deadbeef,代码行数:101,代码来源:main.c
示例4: rvmInitOptions
jboolean rvmInitOptions(int argc, char* argv[], Options* options, jboolean ignoreRvmArgs) {
char path[PATH_MAX];
if (!realpath(argv[0], path)) {
return FALSE;
}
strcpy(options->executablePath, path);
jint i = strlen(path);
while (i >= 0 && path[i] != '/') {
path[i--] = '\0';
}
if (i >= 0 && path[i] == '/') {
path[i] = '\0';
}
strcpy(options->basePath, path);
jint firstJavaArg = 1;
for (i = 1; i < argc; i++) {
if (startsWith(argv[i], "-rvm:")) {
if (!ignoreRvmArgs) {
char* arg = &argv[i][5];
if (startsWith(arg, "log=trace")) {
if (options->logLevel == 0) options->logLevel = LOG_LEVEL_TRACE;
} else if (startsWith(arg, "log=debug")) {
if (options->logLevel == 0) options->logLevel = LOG_LEVEL_DEBUG;
} else if (startsWith(arg, "log=info")) {
if (options->logLevel == 0) options->logLevel = LOG_LEVEL_INFO;
} else if (startsWith(arg, "log=warn")) {
if (options->logLevel == 0) options->logLevel = LOG_LEVEL_WARN;
} else if (startsWith(arg, "log=error")) {
if (options->logLevel == 0) options->logLevel = LOG_LEVEL_ERROR;
} else if (startsWith(arg, "log=fatal")) {
if (options->logLevel == 0) options->logLevel = LOG_LEVEL_FATAL;
} else if (startsWith(arg, "log=silent")) {
if (options->logLevel == 0) options->logLevel = LOG_LEVEL_SILENT;
} else if (startsWith(arg, "mx") || startsWith(arg, "ms")) {
char* unit;
jlong n = strtol(&arg[2], &unit, 10);
if (n > 0) {
if (unit[0] != '\0') {
switch (unit[0]) {
case 'g':
case 'G':
n *= 1024 * 1024 * 1024;
break;
case 'm':
case 'M':
n *= 1024 * 1024;
break;
case 'k':
case 'K':
n *= 1024;
break;
}
}
}
if (startsWith(arg, "mx")) {
options->maxHeapSize = n;
} else {
options->initialHeapSize = n;
}
} else if (startsWith(arg, "MainClass=")) {
if (!options->mainClass) {
char* s = strdup(&arg[10]);
jint j;
for (j = 0; s[j] != 0; j++) {
if (s[j] == '.') s[j] = '/';
}
options->mainClass = s;
}
}
}
firstJavaArg++;
} else {
break;
}
}
options->commandLineArgs = NULL;
options->commandLineArgsCount = argc - firstJavaArg;
if (options->commandLineArgsCount > 0) {
options->commandLineArgs = &argv[firstJavaArg];
}
return options->mainClass != NULL;
}
开发者ID:tobium,项目名称:robovm,代码行数:88,代码来源:init.c
示例5: append_path
// Resolve a path and append it to the CLI settings structure
// The FSEvents API will, internally, resolve paths using a similar scheme.
// Performing this ahead of time makes things less confusing, IMHO.
static void append_path(const char* path)
{
#ifdef DEBUG
fprintf(stderr, "\n");
fprintf(stderr, "append_path called for: %s\n", path);
#endif
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
#ifdef DEBUG
fprintf(stderr, "compiled against 10.6+, using CFURLCreateFileReferenceURL\n");
#endif
CFURLRef url = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8*)path, (CFIndex)strlen(path), false);
CFURLRef placeholder = CFURLCopyAbsoluteURL(url);
CFRelease(url);
CFMutableArrayRef imaginary = NULL;
// if we don't have an existing url, spin until we get to a parent that
// does exist, saving any imaginary components for appending back later
while(!CFURLResourceIsReachable(placeholder, NULL)) {
#ifdef DEBUG
fprintf(stderr, "path does not exist\n");
#endif
CFStringRef child;
if (imaginary == NULL) {
imaginary = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
}
child = CFURLCopyLastPathComponent(placeholder);
CFArrayInsertValueAtIndex(imaginary, 0, child);
CFRelease(child);
url = CFURLCreateCopyDeletingLastPathComponent(NULL, placeholder);
CFRelease(placeholder);
placeholder = url;
#ifdef DEBUG
fprintf(stderr, "parent: ");
CFShow(placeholder);
#endif
}
#ifdef DEBUG
fprintf(stderr, "path exists\n");
#endif
// realpath() doesn't always return the correct case for a path, so this
// is a funky workaround that converts a path into a (volId/inodeId) pair
// and asks what the path should be for that. since it looks at the actual
// inode instead of returning the same case passed in like realpath()
// appears to do for HFS+, it should always be correct.
url = CFURLCreateFileReferenceURL(NULL, placeholder, NULL);
CFRelease(placeholder);
placeholder = CFURLCreateFilePathURL(NULL, url, NULL);
CFRelease(url);
#ifdef DEBUG
fprintf(stderr, "path resolved to: ");
CFShow(placeholder);
#endif
// if we stripped off any imaginary path components, append them back on
if (imaginary != NULL) {
CFIndex count = CFArrayGetCount(imaginary);
for (CFIndex i = 0; i<count; i++) {
CFStringRef component = CFArrayGetValueAtIndex(imaginary, i);
#ifdef DEBUG
fprintf(stderr, "appending component: ");
CFShow(component);
#endif
url = CFURLCreateCopyAppendingPathComponent(NULL, placeholder, component, false);
CFRelease(placeholder);
placeholder = url;
}
CFRelease(imaginary);
}
#ifdef DEBUG
fprintf(stderr, "result: ");
CFShow(placeholder);
#endif
CFStringRef cfPath = CFURLCopyFileSystemPath(placeholder, kCFURLPOSIXPathStyle);
CFArrayAppendValue(config.paths, cfPath);
CFRelease(cfPath);
CFRelease(placeholder);
#else
#ifdef DEBUG
fprintf(stderr, "compiled against 10.5, using realpath()\n");
#endif
//.........这里部分代码省略.........
开发者ID:nateyu,项目名称:rb-fsevent,代码行数:101,代码来源:main.c
示例6: ShowFileSystemSize
/*
* Displays size of file system and percent of data blocks and inodes used.
*/
void ShowFileSystemSize(char *fileSystem)
{
#ifndef _WIN32 /* FIXME */
char realPath[PATH_MAX];
char *fileSystemUnitStr;
long long int totalFileSystemSize;
long long int freeFileSystemSize;
long long int totalInodes;
long long int freeInodes;
double totalFileSystemSizeHR;
double usedFileSystemPercentage;
double usedInodePercentage;
#ifdef __sun /* SunOS does not support statfs(), instead uses statvfs() */
struct statvfs statusBuffer;
#else /* !__sun */
struct statfs statusBuffer;
#endif /* __sun */
#ifdef __sun
if (statvfs(fileSystem, &statusBuffer) != 0) {
ERR("unable to statvfs() file system");
}
#else /* !__sun */
if (statfs(fileSystem, &statusBuffer) != 0) {
ERR("unable to statfs() file system");
}
#endif /* __sun */
/* data blocks */
#ifdef __sun
totalFileSystemSize = statusBuffer.f_blocks * statusBuffer.f_frsize;
freeFileSystemSize = statusBuffer.f_bfree * statusBuffer.f_frsize;
#else /* !__sun */
totalFileSystemSize = statusBuffer.f_blocks * statusBuffer.f_bsize;
freeFileSystemSize = statusBuffer.f_bfree * statusBuffer.f_bsize;
#endif /* __sun */
usedFileSystemPercentage = (1 - ((double)freeFileSystemSize
/ (double)totalFileSystemSize)) * 100;
totalFileSystemSizeHR =
(double)totalFileSystemSize / (double)(1<<30);
fileSystemUnitStr = "GiB";
if (totalFileSystemSizeHR > 1024) {
totalFileSystemSizeHR = (double)totalFileSystemSize / (double)((long long)1<<40);
fileSystemUnitStr = "TiB";
}
/* inodes */
totalInodes = statusBuffer.f_files;
freeInodes = statusBuffer.f_ffree;
usedInodePercentage =
(1 - ((double)freeInodes / (double)totalInodes)) * 100;
/* show results */
if (realpath(fileSystem, realPath) == NULL) {
ERR("unable to use realpath()");
}
fprintf(stdout, "Path: %s\n", realPath);
fprintf(stdout, "FS: %.1f %s Used FS: %2.1f%% ",
totalFileSystemSizeHR, fileSystemUnitStr,
usedFileSystemPercentage);
fprintf(stdout, "Inodes: %.1f Mi Used Inodes: %2.1f%%\n",
(double)totalInodes / (double)(1<<20),
usedInodePercentage);
fflush(stdout);
#endif /* !_WIN32 */
return;
}
static void doSyslogd(void)
{
struct sockaddr_un sunx;
socklen_t addrLength;
int sock_fd;
fd_set fds;
/* Set up signal handlers. */
signal(SIGINT, quit_signal);
signal(SIGTERM, quit_signal);
signal(SIGQUIT, quit_signal);
signal(SIGHUP, SIG_IGN);
signal(SIGCHLD, SIG_IGN);
#ifdef SIGCLD
signal(SIGCLD, SIG_IGN);
#endif
signal(SIGALRM, domark);
alarm(MarkInterval);
/* Create the syslog file so realpath() can work. */
if (realpath(_PATH_LOG, lfile) != NULL) {
unlink(lfile);
}
memset(&sunx, 0, sizeof(sunx));
sunx.sun_family = AF_UNIX;
strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path));
if ((sock_fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
bb_perror_msg_and_die("Couldn't get file descriptor for socket "
_PATH_LOG);
}
addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path);
if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) {
bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG);
}
if (chmod(lfile, 0666) < 0) {
bb_perror_msg_and_die("Could not set permission on " _PATH_LOG);
}
#ifdef CONFIG_FEATURE_IPC_SYSLOG
if (circular_logging == TRUE) {
ipcsyslog_init();
}
#endif
#ifdef CONFIG_FEATURE_REMOTE_LOG
if (doRemoteLog == TRUE) {
init_RemoteLog();
}
#endif
logMessage(LOG_SYSLOG | LOG_INFO, "syslogd started: " BB_BANNER);
for (;;) {
FD_ZERO(&fds);
FD_SET(sock_fd, &fds);
if (select(sock_fd + 1, &fds, NULL, NULL, NULL) < 0) {
if (errno == EINTR) {
/* alarm may have happened. */
continue;
}
bb_perror_msg_and_die("select error");
}
if (FD_ISSET(sock_fd, &fds)) {
int i;
#if MAXLINE > BUFSIZ
# define TMP_BUF_SZ BUFSIZ
#else
# define TMP_BUF_SZ MAXLINE
#endif
#define tmpbuf bb_common_bufsiz1
if ((i = recv(sock_fd, tmpbuf, TMP_BUF_SZ, 0)) > 0) {
tmpbuf[i] = '\0';
serveConnection(tmpbuf, i);
} else {
bb_perror_msg_and_die("UNIX socket error");
}
} /* FD_ISSET() */
} /* for main loop */
}
开发者ID:K0T0LI,项目名称:busybox,代码行数:86,代码来源:syslogd.c
示例10: main
//.........这里部分代码省略.........
}
else
{
char buffer[255] ;
prefix = strdup( "rascaf" ) ;
sprintf( buffer, "%s.out", prefix ) ;
fpOut = fopen( buffer, "w" ) ;
}
if ( genomeFile != NULL )
{
genome.Open( alignments, genomeFile ) ;
alignments.Rewind() ;
}
if ( outputConnectionSequence == true && genomeFile == NULL )
{
fprintf( stderr, "Must use -f to specify assembly file when using -cs\n" ) ;
exit( EXIT_FAILURE ) ;
}
// 74619
//printf( "%c\n", genome.GetNucleotide( 74619, 4 ) ) ;
//exit(0) ;
// Build the graph
ret = blocks.BuildExonBlocks( alignments, genome ) ;
alignments.Rewind() ;
fprintf( stderr, "Found %d exon blocks.\n", ret ) ;
if ( clippedAlignments.IsOpened() )
{
fprintf( stderr, "Extend exon blocks with clipped alignments.\n" ) ;
Blocks extendBlocks ;
extendBlocks.BuildExonBlocks( clippedAlignments, genome ) ;
clippedAlignments.Rewind() ;
ret = blocks.ExtendExonBlocks( extendBlocks ) ;
fprintf( stderr, "Found %d exon blocks after extension.\n", ret ) ;
}
blocks.GetAlignmentsInfo( alignments ) ;
alignments.Rewind() ;
ret = blocks.BuildGeneBlocks( alignments, genome ) ;
alignments.Rewind() ;
fprintf( stderr, "Found %d gene blocks.\n", ret ) ;
blocks.BuildGeneBlockGraph( alignments ) ;
if ( clippedAlignments.IsOpened() )
{
blocks.AddGeneBlockGraphByClippedAlignments( clippedAlignments ) ;
}
// Cleaning
blocks.CleanGeneBlockGraph( alignments, genome ) ;
// Scaffolding
Scaffold scaffold( blocks, genome ) ;
//scaffold.Init( blocks ) ;
int componentCnt = scaffold.BuildComponent() ;
fprintf( stderr, "Found %d non-trivial gene block components.\n", componentCnt ) ;
// Possible for parallelization
for ( i = 0 ; i < componentCnt ; ++i )
{
scaffold.ScaffoldComponent( i ) ;
}
scaffold.ScaffoldGenome() ;
// Output the command line
fprintf( fpOut, "command line: " ) ;
char *fullpath = (char *)malloc( sizeof( char ) * 4096 ) ;
for ( i = 0 ; i < argc ; ++i )
{
char c = ' ' ;
if ( i == argc - 1 )
c = '\n' ;
if ( i > 0 && !strcmp( argv[i - 1], "-b" ) )
{
if ( realpath( argv[i], fullpath ) == NULL )
{
fprintf( stderr, "Failed to resolve the path of file %s.\n", argv[i] ) ;
exit( 1 ) ;
}
fprintf( fpOut, "%s%c", fullpath, c ) ;
}
else if ( i > 0 && !strcmp( argv[i - 1], "-f" ) )
{
if ( realpath( argv[i], fullpath ) == NULL )
{
fprintf( stderr, "Failed to resolve the path of file %s.\n", argv[i] ) ;
exit( 1 ) ;
}
fprintf( fpOut, "%s%c", fullpath, c ) ;
}
else
fprintf( fpOut, "%s%c", argv[i], c ) ;
}
free( fullpath ) ;
scaffold.Output( fpOut, alignments ) ;
return 0 ;
}
开发者ID:mourisl,项目名称:Rascaf,代码行数:101,代码来源:main.cpp
示例11: main
//.........这里部分代码省略.........
touchFlag = FALSE; /* Actually update targets */
debug = 0; /* No debug verbosity, please. */
jobsRunning = FALSE;
maxJobs = DEFMAXLOCAL; /* Set default local max concurrency */
maxJobTokens = maxJobs;
compatMake = FALSE; /* No compat mode */
ignorePWD = FALSE;
/*
* Initialize the parsing, directory and variable modules to prepare
* for the reading of inclusion paths and variable settings on the
* command line
*/
/*
* Initialize various variables.
* MAKE also gets this name, for compatibility
* .MAKEFLAGS gets set to the empty string just in case.
* MFLAGS also gets initialized empty, for compatibility.
*/
Parse_Init();
if (argv[0][0] == '/' || strchr(argv[0], '/') == NULL) {
/*
* Leave alone if it is an absolute path, or if it does
* not contain a '/' in which case we need to find it in
* the path, like execvp(3) and the shells do.
*/
p1 = argv[0];
} else {
/*
* A relative path, canonicalize it.
*/
p1 = realpath(argv[0], mdpath);
if (!p1 || *p1 != '/' || stat(p1, &sb) < 0) {
p1 = argv[0]; /* realpath failed */
}
}
Var_Set("MAKE", p1, VAR_GLOBAL, 0);
Var_Set(".MAKE", p1, VAR_GLOBAL, 0);
Var_Set(MAKEFLAGS, "", VAR_GLOBAL, 0);
Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL, 0);
Var_Set("MFLAGS", "", VAR_GLOBAL, 0);
Var_Set(".ALLTARGETS", "", VAR_GLOBAL, 0);
/*
* Set some other useful macros
*/
{
char tmp[64];
const char *ep;
if (!(ep = getenv(MAKE_LEVEL))) {
#ifdef MAKE_LEVEL_SAFE
if (!(ep = getenv(MAKE_LEVEL_SAFE)))
#endif
ep = "0";
}
Var_Set(MAKE_LEVEL, ep, VAR_GLOBAL, 0);
snprintf(tmp, sizeof(tmp), "%u", myPid);
Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0);
snprintf(tmp, sizeof(tmp), "%u", getppid());
Var_Set(".MAKE.PPID", tmp, VAR_GLOBAL, 0);
}
Job_SetPrefix();
// whitelist for /home/user directory
void fs_whitelist(void) {
char *homedir = cfg.homedir;
assert(homedir);
ProfileEntry *entry = cfg.profile;
if (!entry)
return;
// realpath function will fail with ENOENT if the file is not found
// we need to expand the path before installing a new, empty home directory
while (entry) {
// handle only whitelist commands
if (strncmp(entry->data, "whitelist ", 10)) {
entry = entry->next;
continue;
}
char *new_name = expand_home(entry->data + 10, cfg.homedir);
assert(new_name);
char *fname = realpath(new_name, NULL);
free(new_name);
if (fname) {
// change file name in entry->data
if (strcmp(fname, entry->data + 10) != 0) {
char *newdata;
if (asprintf(&newdata, "whitelist %s", fname) == -1)
errExit("asprintf");
entry->data = newdata;
if (arg_debug)
printf("Replaced whitelist path: %s\n", entry->data);
}
free(fname);
}
else {
// file not found, blank the entry in the list
if (arg_debug)
printf("Removed whitelist path: %s\n", entry->data);
*entry->data = '\0';
}
entry = entry->next;
}
// create /tmp/firejail/mnt/whome directory
fs_build_mnt_dir();
int rv = mkdir(WHITELIST_HOME_DIR, S_IRWXU | S_IRWXG | S_IRWXO);
if (rv == -1)
errExit("mkdir");
if (chown(WHITELIST_HOME_DIR, getuid(), getgid()) < 0)
errExit("chown");
if (chmod(WHITELIST_HOME_DIR, 0755) < 0)
errExit("chmod");
// keep a copy of real home dir in /tmp/firejail/mnt/whome
if (mount(cfg.homedir, WHITELIST_HOME_DIR, NULL, MS_BIND|MS_REC, NULL) < 0)
errExit("mount bind");
// start building the new home directory by mounting a tmpfs fielsystem
fs_private();
// go through profile rules again, and interpret whitelist commands
entry = cfg.profile;
while (entry) {
// handle only whitelist commands
if (strncmp(entry->data, "whitelist ", 10)) {
entry = entry->next;
continue;
}
whitelist_path(entry->data + 10);
entry = entry->next;
}
// mask the real home directory, currently mounted on /tmp/firejail/mnt/whome
if (mount("tmpfs", WHITELIST_HOME_DIR, "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC, "mode=755,gid=0") < 0)
errExit("mount tmpfs");
}
请发表评论