Jay Sorg 13 years ago
parent b36f7d346c
commit f10e5bbfd5

@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2010 Jay Sorg
Copyright (c) 2004-2012 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@ -79,9 +79,11 @@ extern char** environ;
#define INADDR_NONE ((unsigned long)-1)
#endif
static char g_temp_base[64] = "";
/*****************************************************************************/
void APP_CC
g_init(void)
g_init(const char* app_name)
{
#if defined(_WIN32)
WSADATA wsadata;
@ -89,6 +91,17 @@ g_init(void)
WSAStartup(2, &wsadata);
#endif
setlocale(LC_CTYPE, "");
if (app_name != 0)
{
if (app_name[0] == 0)
{
snprintf(g_temp_base, sizeof(g_temp_base), "/tmp/%s-XXXXXX", app_name);
if (mkdtemp(g_temp_base) == 0)
{
printf("g_init: mkdtemp failed [%s]\n", g_temp_base);
}
}
}
}
/*****************************************************************************/
@ -98,6 +111,7 @@ g_deinit(void)
#if defined(_WIN32)
WSACleanup();
#endif
g_remove_dir(g_temp_base);
}
/*****************************************************************************/
@ -700,39 +714,61 @@ g_create_wait_obj(char* name)
#else
tbus obj;
struct sockaddr_un sa;
size_t len = 0;
tbus sck = -1;
int i = 0;
g_memset(&sa,0,sizeof(struct sockaddr_un));
size_t len;
tbus sck;
int i;
int safety;
int unnamed;
if (g_temp_base[0] == 0)
{
return 0;
}
sck = socket(PF_UNIX, SOCK_DGRAM, 0);
if (sck < 0)
{
return 0;
}
memset(&sa, 0, sizeof(sa));
safety = 0;
g_memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
if ((name == 0) || (strlen(name) == 0))
unnamed = 1;
if (name != 0)
{
g_random((char*)&i, sizeof(i));
sprintf(sa.sun_path, "/tmp/auto%8.8x", i);
while (g_file_exist(sa.sun_path))
if (name[0] != 0)
{
g_random((char*)&i, sizeof(i));
sprintf(sa.sun_path, "/tmp/auto%8.8x", i);
unnamed = 0;
}
}
else
if (unnamed)
{
sprintf(sa.sun_path, "/tmp/%s", name);
do
{
if (safety > 100)
{
break;
}
safety++;
g_random((char*)&i, sizeof(i));
len = sizeof(sa.sun_path);
g_snprintf(sa.sun_path, len, "%s/auto_%8.8x", g_temp_base, i);
len = sizeof(sa);
} while (bind(sck, (struct sockaddr*)&sa, len) < 0);
}
unlink(sa.sun_path);
len = sizeof(sa);
if (bind(sck, (struct sockaddr*)&sa, len) < 0)
else
{
close(sck);
return 0;
do
{
if (safety > 100)
{
break;
}
safety++;
g_random((char*)&i, sizeof(i));
len = sizeof(sa.sun_path);
g_snprintf(sa.sun_path, len, "%s/%s_%8.8x", g_temp_base, name, i);
len = sizeof(sa);
} while (bind(sck, (struct sockaddr*)&sa, len) < 0);
}
obj = (tbus)sck;
return obj;

@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2010 Jay Sorg
Copyright (c) 2004-2012 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@ -32,7 +32,7 @@
#include "arch.h"
void APP_CC
g_init(void);
g_init(const char* app_name);
void APP_CC
g_deinit(void);
void* APP_CC

@ -637,7 +637,7 @@ main(int argc, char** argv)
char text[256] = "";
char* display_text = (char *)NULL;
g_init(); /* os_calls */
g_init("xrdp-chansrv"); /* os_calls */
read_ini();
pid = g_getpid();
LOG(1, ("main: app started pid %d(0x%8.8x)", pid, pid));
@ -681,5 +681,6 @@ main(int argc, char** argv)
/* cleanup */
main_cleanup();
LOG(1, ("main: app exiting pid %d(0x%8.8x)", pid, pid));
g_deinit();
return 0;
}

@ -138,6 +138,7 @@ main(int argc, char** argv)
char text[256];
char pid_file[256];
g_init("xrdp-sesman");
g_snprintf(pid_file, 255, "%s/xrdp-sesman.pid", XRDP_PID_PATH);
if (1 == argc)
{
@ -350,6 +351,7 @@ main(int argc, char** argv)
log_end(&(g_cfg->log));
}
g_deinit();
return 0;
}

@ -80,6 +80,7 @@ main(int argc, char** argv)
int lerror = 0;
char exe_path[262];
g_init("xrdp-sessvc");
g_memset(exe_path,0,sizeof(exe_path));
if (argc < 3)
@ -145,5 +146,6 @@ main(int argc, char** argv)
g_sleep(1);
}
g_writeln("xrdp-sessvc: clean exit");
g_deinit();
return 0;
}

@ -235,7 +235,7 @@ main(int argc, char** argv)
char text[256];
char pid_file[256];
g_init();
g_init("xrdp");
ssl_init();
/* check compiled endian with actual endian */
test = 1;
@ -432,5 +432,6 @@ main(int argc, char** argv)
/* delete the xrdp.pid file */
g_file_delete(pid_file);
g_free(startup_params);
g_deinit();
return 0;
}

Loading…
Cancel
Save