This commit is contained in:
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
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
@ -79,9 +79,11 @@ extern char** environ;
|
|||||||
#define INADDR_NONE ((unsigned long)-1)
|
#define INADDR_NONE ((unsigned long)-1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static char g_temp_base[64] = "";
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
g_init(void)
|
g_init(const char* app_name)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
WSADATA wsadata;
|
WSADATA wsadata;
|
||||||
@ -89,6 +91,17 @@ g_init(void)
|
|||||||
WSAStartup(2, &wsadata);
|
WSAStartup(2, &wsadata);
|
||||||
#endif
|
#endif
|
||||||
setlocale(LC_CTYPE, "");
|
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)
|
#if defined(_WIN32)
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
#endif
|
#endif
|
||||||
|
g_remove_dir(g_temp_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@ -700,39 +714,61 @@ g_create_wait_obj(char* name)
|
|||||||
#else
|
#else
|
||||||
tbus obj;
|
tbus obj;
|
||||||
struct sockaddr_un sa;
|
struct sockaddr_un sa;
|
||||||
size_t len = 0;
|
size_t len;
|
||||||
tbus sck = -1;
|
tbus sck;
|
||||||
int i = 0;
|
int i;
|
||||||
|
int safety;
|
||||||
g_memset(&sa,0,sizeof(struct sockaddr_un));
|
int unnamed;
|
||||||
|
|
||||||
|
if (g_temp_base[0] == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
sck = socket(PF_UNIX, SOCK_DGRAM, 0);
|
sck = socket(PF_UNIX, SOCK_DGRAM, 0);
|
||||||
if (sck < 0)
|
if (sck < 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memset(&sa, 0, sizeof(sa));
|
safety = 0;
|
||||||
|
g_memset(&sa, 0, sizeof(sa));
|
||||||
sa.sun_family = AF_UNIX;
|
sa.sun_family = AF_UNIX;
|
||||||
if ((name == 0) || (strlen(name) == 0))
|
unnamed = 1;
|
||||||
|
if (name != 0)
|
||||||
{
|
{
|
||||||
g_random((char*)&i, sizeof(i));
|
if (name[0] != 0)
|
||||||
sprintf(sa.sun_path, "/tmp/auto%8.8x", i);
|
|
||||||
while (g_file_exist(sa.sun_path))
|
|
||||||
{
|
{
|
||||||
g_random((char*)&i, sizeof(i));
|
unnamed = 0;
|
||||||
sprintf(sa.sun_path, "/tmp/auto%8.8x", i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (unnamed)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf(sa.sun_path, "/tmp/%s", name);
|
do
|
||||||
}
|
|
||||||
unlink(sa.sun_path);
|
|
||||||
len = sizeof(sa);
|
|
||||||
if (bind(sck, (struct sockaddr*)&sa, len) < 0)
|
|
||||||
{
|
{
|
||||||
close(sck);
|
if (safety > 100)
|
||||||
return 0;
|
{
|
||||||
|
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;
|
obj = (tbus)sck;
|
||||||
return obj;
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
@ -32,7 +32,7 @@
|
|||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
|
|
||||||
void APP_CC
|
void APP_CC
|
||||||
g_init(void);
|
g_init(const char* app_name);
|
||||||
void APP_CC
|
void APP_CC
|
||||||
g_deinit(void);
|
g_deinit(void);
|
||||||
void* APP_CC
|
void* APP_CC
|
||||||
|
@ -637,7 +637,7 @@ main(int argc, char** argv)
|
|||||||
char text[256] = "";
|
char text[256] = "";
|
||||||
char* display_text = (char *)NULL;
|
char* display_text = (char *)NULL;
|
||||||
|
|
||||||
g_init(); /* os_calls */
|
g_init("xrdp-chansrv"); /* os_calls */
|
||||||
read_ini();
|
read_ini();
|
||||||
pid = g_getpid();
|
pid = g_getpid();
|
||||||
LOG(1, ("main: app started pid %d(0x%8.8x)", pid, pid));
|
LOG(1, ("main: app started pid %d(0x%8.8x)", pid, pid));
|
||||||
@ -681,5 +681,6 @@ main(int argc, char** argv)
|
|||||||
/* cleanup */
|
/* cleanup */
|
||||||
main_cleanup();
|
main_cleanup();
|
||||||
LOG(1, ("main: app exiting pid %d(0x%8.8x)", pid, pid));
|
LOG(1, ("main: app exiting pid %d(0x%8.8x)", pid, pid));
|
||||||
|
g_deinit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -138,6 +138,7 @@ main(int argc, char** argv)
|
|||||||
char text[256];
|
char text[256];
|
||||||
char pid_file[256];
|
char pid_file[256];
|
||||||
|
|
||||||
|
g_init("xrdp-sesman");
|
||||||
g_snprintf(pid_file, 255, "%s/xrdp-sesman.pid", XRDP_PID_PATH);
|
g_snprintf(pid_file, 255, "%s/xrdp-sesman.pid", XRDP_PID_PATH);
|
||||||
if (1 == argc)
|
if (1 == argc)
|
||||||
{
|
{
|
||||||
@ -350,6 +351,7 @@ main(int argc, char** argv)
|
|||||||
log_end(&(g_cfg->log));
|
log_end(&(g_cfg->log));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_deinit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ main(int argc, char** argv)
|
|||||||
int lerror = 0;
|
int lerror = 0;
|
||||||
char exe_path[262];
|
char exe_path[262];
|
||||||
|
|
||||||
|
g_init("xrdp-sessvc");
|
||||||
g_memset(exe_path,0,sizeof(exe_path));
|
g_memset(exe_path,0,sizeof(exe_path));
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
@ -145,5 +146,6 @@ main(int argc, char** argv)
|
|||||||
g_sleep(1);
|
g_sleep(1);
|
||||||
}
|
}
|
||||||
g_writeln("xrdp-sessvc: clean exit");
|
g_writeln("xrdp-sessvc: clean exit");
|
||||||
|
g_deinit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ main(int argc, char** argv)
|
|||||||
char text[256];
|
char text[256];
|
||||||
char pid_file[256];
|
char pid_file[256];
|
||||||
|
|
||||||
g_init();
|
g_init("xrdp");
|
||||||
ssl_init();
|
ssl_init();
|
||||||
/* check compiled endian with actual endian */
|
/* check compiled endian with actual endian */
|
||||||
test = 1;
|
test = 1;
|
||||||
@ -432,5 +432,6 @@ main(int argc, char** argv)
|
|||||||
/* delete the xrdp.pid file */
|
/* delete the xrdp.pid file */
|
||||||
g_file_delete(pid_file);
|
g_file_delete(pid_file);
|
||||||
g_free(startup_params);
|
g_free(startup_params);
|
||||||
|
g_deinit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user