Repository: incubator-hawq Updated Branches: refs/heads/master eab41edab -> 27d72576f
HAWQ-940. Fix Kerberos ticket expired for libyarn operations Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/27d72576 Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/27d72576 Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/27d72576 Branch: refs/heads/master Commit: 27d72576fdbb03a8e0b8ea21408c6079febc0625 Parents: eab41ed Author: Wen Lin <[email protected]> Authored: Fri Jul 22 12:38:06 2016 +0800 Committer: Wen Lin <[email protected]> Committed: Fri Jul 22 12:38:06 2016 +0800 ---------------------------------------------------------------------- .../resourcebroker/resourcebroker_LIBYARN.c | 2 - .../resourcebroker_LIBYARN_proc.c | 144 +++++++++---------- 2 files changed, 72 insertions(+), 74 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/27d72576/src/backend/resourcemanager/resourcebroker/resourcebroker_LIBYARN.c ---------------------------------------------------------------------- diff --git a/src/backend/resourcemanager/resourcebroker/resourcebroker_LIBYARN.c b/src/backend/resourcemanager/resourcebroker/resourcebroker_LIBYARN.c index 37e3bca..845cc89 100644 --- a/src/backend/resourcemanager/resourcebroker/resourcebroker_LIBYARN.c +++ b/src/backend/resourcemanager/resourcebroker/resourcebroker_LIBYARN.c @@ -470,8 +470,6 @@ int RB_LIBYARN_handleNotification(void) uint32_t messagehead[2]; uint32_t messageid; - - FD_ZERO(&rfds); FD_SET(fd, &rfds); timeout.tv_sec = 0; http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/27d72576/src/backend/resourcemanager/resourcebroker/resourcebroker_LIBYARN_proc.c ---------------------------------------------------------------------- diff --git a/src/backend/resourcemanager/resourcebroker/resourcebroker_LIBYARN_proc.c b/src/backend/resourcemanager/resourcebroker/resourcebroker_LIBYARN_proc.c index 5a6e6a2..fc0a6db 100644 --- a/src/backend/resourcemanager/resourcebroker/resourcebroker_LIBYARN_proc.c +++ b/src/backend/resourcemanager/resourcebroker/resourcebroker_LIBYARN_proc.c @@ -136,28 +136,30 @@ int ResBrokerMain(void) ResBrokerKeepRun = true; - /* Load parameters */ - int res = loadParameters(); - if ( res != FUNC_RETURN_OK ) { - elog(WARNING, "Resource broker loads invalid yarn parameters"); - } + /* Load parameters */ + int res = loadParameters(); + if ( res != FUNC_RETURN_OK ) { + elog(WARNING, "Resource broker loads invalid yarn parameters"); + } - /* Set signal behavior */ - PG_SETMASK(&BlockSig); - pqsignal(SIGHUP , SIG_IGN); - pqsignal(SIGINT , quitResBroker); - pqsignal(SIGTERM, quitResBroker); - pqsignal(SIGQUIT, SIG_DFL); - pqsignal(SIGPIPE, SIG_IGN); - pqsignal(SIGUSR1, SIG_IGN); - pqsignal(SIGUSR2, SIG_IGN); - pqsignal(SIGCHLD, SIG_IGN); - pqsignal(SIGTTIN, SIG_IGN); - pqsignal(SIGTTOU, SIG_IGN); - PG_SETMASK(&UnBlockSig); + /* Set signal behavior */ + PG_SETMASK(&BlockSig); + pqsignal(SIGHUP , SIG_IGN); + pqsignal(SIGINT , quitResBroker); + pqsignal(SIGTERM, quitResBroker); + pqsignal(SIGQUIT, SIG_DFL); + pqsignal(SIGPIPE, SIG_IGN); + pqsignal(SIGUSR1, SIG_IGN); + pqsignal(SIGUSR2, SIG_IGN); + /* call system() needs set SIG_DFL for SIGCHLD */ + pqsignal(SIGCHLD, SIG_DFL); + pqsignal(SIGTTIN, SIG_IGN); + pqsignal(SIGTTOU, SIG_IGN); + PG_SETMASK(&UnBlockSig); res = ResBrokerMainInternal(); + pqsignal(SIGCHLD, SIG_IGN); elog(LOG, "YARN mode resource broker goes into exit phase."); return res; } @@ -195,6 +197,12 @@ int ResBrokerMainInternal(void) continue; } + /* refresh kerberos ticket */ + if (enable_secure_filesystem && !login()) + { + elog(WARNING, "Resource broker failed to refresh kerberos ticket."); + } + /* * If the connection between YARN and YARN resource broker is not * created, try to build up connection and register application. @@ -339,71 +347,63 @@ char * ExtractPrincipalFromTicketCache(const char* cache) char *priName = NULL, *retval = NULL; const char *errorMsg = NULL; - /* - * refresh kerberos ticket - */ - if (!login()) { - elog(WARNING, "Cannot login kerberos."); - return NULL; - } + if (cache) { + if (0 != setenv("KRB5CCNAME", cache, 1)) { + elog(WARNING, "Cannot set env parameter \"KRB5CCNAME\" when extract principal from cache:%s", cache); + return NULL; + } + } - if (cache) { - if (0 != setenv("KRB5CCNAME", cache, 1)) { - elog(WARNING, "Cannot set env parameter \"KRB5CCNAME\" when extract principal from cache:%s", cache); - return NULL; - } - } + do { + if (0 != (ec = krb5_init_context(&cxt))) { + break; + } - do { - if (0 != (ec = krb5_init_context(&cxt))) { - break; - } + if (0 != (ec = krb5_cc_default(cxt, &ccache))) { + break; + } - if (0 != (ec = krb5_cc_default(cxt, &ccache))) { - break; - } + if (0 != (ec = krb5_cc_get_principal(cxt, ccache, &principal))) { + break; + } - if (0 != (ec = krb5_cc_get_principal(cxt, ccache, &principal))) { - break; - } + if (0 != (ec = krb5_unparse_name(cxt, principal, &priName))) { + break; + } + } while (0); - if (0 != (ec = krb5_unparse_name(cxt, principal, &priName))) { - break; - } - } while (0); - - if (!ec) { - retval = strdup(priName); - } else { - if (cxt) { - errorMsg = krb5_get_error_message(cxt, ec); - } else { - errorMsg = "Cannot initialize kerberos context"; - } - } + if (!ec) { + retval = strdup(priName); + } else { + if (cxt) { + errorMsg = krb5_get_error_message(cxt, ec); + } else { + errorMsg = "Cannot initialize kerberos context"; + } + } - if (priName != NULL) { - krb5_free_unparsed_name(cxt, priName); - } + if (priName != NULL) { + krb5_free_unparsed_name(cxt, priName); + } - if (principal != NULL) { - krb5_free_principal(cxt, principal); - } + if (principal != NULL) { + krb5_free_principal(cxt, principal); + } - if (ccache != NULL) { - krb5_cc_close(cxt, ccache); - } + if (ccache != NULL) { + krb5_cc_close(cxt, ccache); + } - if (cxt != NULL) { - krb5_free_context(cxt); - } + if (cxt != NULL) { + krb5_free_context(cxt); + } - if (errorMsg != NULL) { - elog(WARNING, "Fail to extract principal from cache, because : %s", errorMsg); - return NULL; - } + if (errorMsg != NULL) { + elog(WARNING, "Fail to extract principal from cache, because : %s", errorMsg); + return NULL; + } - return retval; + return retval; } int loadParameters(void)
