--- On Mon, 7/3/11, Otavio Salvador <[email protected]> wrote:
> From: Otavio Salvador <[email protected]>
> Subject: Re: [Freerdp-devel] Exit codes and singleton mode
> To: "Jay Sorg" <[email protected]>
> Cc: "freerdp" <[email protected]>
> Date: Monday, 7 March, 2011, 1:02
> On Mon, Mar 7, 2011 at 02:30, Jay
> Sorg <[email protected]>
> wrote:
> >> Returning reasonable exit codes is much more
> relevant, and it shouldn't
> >> be guarded by special options.
> >
> > I'd have to agree. I don't think we need a special
> option for this,
> > just return what the last thread returns.
>
> This works fine to us; we just added the option to avoid
> changing the
> default behaviour.
>
Here it is. The patch which makes xfreerdp end with the last thread's return as
the program exit code. Please comment.
Thanks
Eduardo Fiss Beloni
[email protected]
55 53 8117 8244
From a1fcc21161fa6614f8729e230ec20e1f57918e30 Mon Sep 17 00:00:00 2001
From: Eduardo Beloni <[email protected]>
Date: Wed, 9 Mar 2011 10:32:38 -0300
Subject: [PATCH] xfreerdp: return code according to the Set Error Info PDU
---
X11/xf_types.h | 21 +++++++++++++++++++++
X11/xfreerdp.c | 24 +++++++++++++++++-------
2 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/X11/xf_types.h b/X11/xf_types.h
index 2041563..2e7338b 100644
--- a/X11/xf_types.h
+++ b/X11/xf_types.h
@@ -85,6 +85,27 @@ struct xf_info
};
typedef struct xf_info xfInfo;
+
+enum STANDARD_EXIT_CODE
+{
+ EX_OK = 0,
+ EX_USAGE = 64,
+ EX_DATAERR = 65,
+ EX_NOINPUT = 66,
+ EX_NOUSER = 67,
+ EX_NOHOST = 68,
+ EX_UNAVAILABLE = 69,
+ EX_SOFTWARE = 70,
+ EX_OSERR = 71,
+ EX_OSFILE = 72,
+ EX_CANTCREAT = 73,
+ EX_IOERR = 74,
+ EX_TEMPFAIL = 75,
+ EX_PROTOCOL = 76,
+ EX_NOPERM = 77,
+ EX_CONFIG = 78,
+};
+
#ifdef WITH_DEBUG
#define DEBUG(fmt, ...) printf("DBG %s (%d): " fmt, __FUNCTION__, __LINE__, ## __VA_ARGS__)
#else
diff --git a/X11/xfreerdp.c b/X11/xfreerdp.c
index 484a86d..45a5056 100644
--- a/X11/xfreerdp.c
+++ b/X11/xfreerdp.c
@@ -41,6 +41,7 @@
static sem_t g_sem;
static volatile int g_thread_count = 0;
+static pthread_t g_last_thread;
static int
set_default_params(xfInfo * xfi)
@@ -541,6 +542,7 @@ run_xfreerdp(xfInfo * xfi)
int max_sck;
fd_set rfds;
fd_set wfds;
+ uint32 disc_reason;
/* create an instance of the library */
inst = freerdp_new(xfi->settings);
@@ -575,7 +577,7 @@ run_xfreerdp(xfInfo * xfi)
if (inst->rdp_connect(inst) != 0)
{
printf("run_xfreerdp: inst->rdp_connect failed\n");
- return 1;
+ return EX_PROTOCOL;
}
if (freerdp_chanman_post_connect(xfi->chan_man, inst) != 0)
{
@@ -651,7 +653,7 @@ run_xfreerdp(xfInfo * xfi)
/* check the libfreerdp fds */
if (inst->rdp_check_fds(inst) != 0)
{
- printf("run_xfreerdp: inst->rdp_check_fds failed\n");
+ printf("run_xfreerdp: inst->rdp_check_fds failed reason %u\n", inst->disc_reason);
break;
}
/* check x fds */
@@ -667,32 +669,38 @@ run_xfreerdp(xfInfo * xfi)
break;
}
}
+
+ disc_reason = inst->disc_reason;
/* cleanup */
freerdp_chanman_close(xfi->chan_man, inst);
inst->rdp_disconnect(inst);
freerdp_free(inst);
xf_uninit(xfi);
- return 0;
+ return disc_reason;
}
static void *
thread_func(void * arg)
{
xfInfo * xfi;
+ uint32 disc_reason;
xfi = (xfInfo *) arg;
- run_xfreerdp(xfi);
+ disc_reason = run_xfreerdp(xfi);
free(xfi->settings);
freerdp_chanman_free(xfi->chan_man);
free(xfi);
- pthread_detach(pthread_self());
g_thread_count--;
if (g_thread_count < 1)
{
+ g_last_thread = pthread_self();
freerdp_sem_signal(&g_sem);
}
- return NULL;
+ else
+ pthread_detach(pthread_self());
+
+ return (void *)disc_reason;
}
int
@@ -702,6 +710,7 @@ main(int argc, char ** argv)
xfInfo * xfi;
pthread_t thread;
int index = 1;
+ int disc_reason = 0;
setlocale(LC_CTYPE, "");
if (argc == 1)
@@ -746,10 +755,11 @@ main(int argc, char ** argv)
{
printf("main thread, waiting for all threads to exit\n");
freerdp_sem_wait(&g_sem);
+ pthread_join(g_last_thread, (void **)&disc_reason);
printf("main thread, all threads did exit\n");
}
freerdp_chanman_uninit();
freerdp_global_finish();
- return 0;
+ return disc_reason;
}
--
1.6.6.1
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Freerdp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freerdp-devel