ack
On Sun, May 1, 2011 at 11:58 AM, Russell Bryant
<russell(a)russellbryant.net> wrote:
Fix mixed space/tab indentation and strip trailing whitespace.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/lib/services_linux.c | 488 +++++++++++++++++++++++-----------------------
1 files changed, 244 insertions(+), 244 deletions(-)
diff --git a/src/lib/services_linux.c b/src/lib/services_linux.c
index 3e5949c..4418331 100644
--- a/src/lib/services_linux.c
+++ b/src/lib/services_linux.c
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright (C) 2010 Andrew Beekhof <andrew(a)beekhof.net>
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -33,18 +33,18 @@
#include "services_private.h"
#include "sigar.h"
-#define set_fd_opts(fd,opts) do { \
- int flag; \
- if ((flag = fcntl(fd, F_GETFL)) >= 0) { \
- if (fcntl(fd, F_SETFL, flag|opts) < 0) { \
- mh_perror(LOG_ERR, "fcntl() write failed"); \
- } \
- } else { \
- mh_perror(LOG_ERR, "fcntl() read failed"); \
- } \
+#define set_fd_opts(fd,opts) do { \
+ int flag; \
+ if ((flag = fcntl(fd, F_GETFL)) >= 0) { \
+ if (fcntl(fd, F_SETFL, flag|opts) < 0) { \
+ mh_perror(LOG_ERR, "fcntl() write failed"); \
+ } \
+ } else { \
+ mh_perror(LOG_ERR, "fcntl() read failed"); \
+ } \
} while(0)
-static gboolean
+static gboolean
read_output(int fd, gpointer user_data)
{
char * data = NULL;
@@ -53,39 +53,39 @@ read_output(int fd, gpointer user_data)
svc_action_t* op = (svc_action_t *)user_data;
if(fd == op->opaque->stderr_fd) {
- is_err = TRUE;
- if(op->stderr_data) {
- len = strlen(op->stderr_data);
- data = op->stderr_data;
- }
+ is_err = TRUE;
+ if(op->stderr_data) {
+ len = strlen(op->stderr_data);
+ data = op->stderr_data;
+ }
} else if(op->stdout_data) {
- len = strlen(op->stdout_data);
- data = op->stdout_data;
+ len = strlen(op->stdout_data);
+ data = op->stdout_data;
}
do {
- char buf[500];
- rc = read(fd, buf, 500);
- if(rc > 0) {
- buf[rc] = 0;
- data = realloc(data, len + rc + 1);
- sprintf(data+len, "%s", buf);
- len += rc;
-
- } else if(errno != EINTR) {
- /* error or EOF
- * Cleanup happens in pipe_done()
- */
- rc = FALSE;
- break;
- }
-
+ char buf[500];
+ rc = read(fd, buf, 500);
+ if(rc > 0) {
+ buf[rc] = 0;
+ data = realloc(data, len + rc + 1);
+ sprintf(data+len, "%s", buf);
+ len += rc;
+
+ } else if(errno != EINTR) {
+ /* error or EOF
+ * Cleanup happens in pipe_done()
+ */
+ rc = FALSE;
+ break;
+ }
+
} while (rc == 500 || rc < 0);
if (data != NULL && is_err) {
- op->stderr_data = data;
+ op->stderr_data = data;
} else if(data != NULL) {
- op->stdout_data = data;
+ op->stdout_data = data;
}
return rc;
@@ -97,7 +97,7 @@ pipe_out_done(gpointer user_data)
svc_action_t* op = (svc_action_t *)user_data;
op->opaque->stdout_gsource = NULL;
if (op->opaque->stdout_fd > STDERR_FILENO) {
- close(op->opaque->stdout_fd);
+ close(op->opaque->stdout_fd);
}
op->opaque->stdout_fd = -1;
}
@@ -108,7 +108,7 @@ pipe_err_done(gpointer user_data)
svc_action_t* op = (svc_action_t *)user_data;
op->opaque->stderr_gsource = NULL;
if (op->opaque->stderr_fd > STDERR_FILENO) {
- close(op->opaque->stderr_fd);
+ close(op->opaque->stderr_fd);
}
op->opaque->stderr_fd = -1;
}
@@ -117,7 +117,7 @@ static void
set_ocf_env(gpointer key, gpointer value, gpointer user_data)
{
if (setenv(key, value, 1) != 0) {
- mh_err("setenv failed in raexecocf.");
+ mh_err("setenv failed in raexecocf.");
}
}
@@ -134,28 +134,28 @@ static void
add_OCF_env_vars(svc_action_t *op)
{
if (strcmp("ocf", op->rclass) != 0) {
- return;
+ return;
}
if(op->params) {
- g_hash_table_foreach(op->params, set_ocf_env_with_prefix, NULL);
+ g_hash_table_foreach(op->params, set_ocf_env_with_prefix, NULL);
}
-
+
set_ocf_env("OCF_RA_VERSION_MAJOR", "1", NULL);
set_ocf_env("OCF_RA_VERSION_MINOR", "0", NULL);
set_ocf_env("OCF_ROOT", OCF_ROOT, NULL);
if(op->rsc) {
- set_ocf_env("OCF_RESOURCE_INSTANCE", op->rsc, NULL);
+ set_ocf_env("OCF_RESOURCE_INSTANCE", op->rsc, NULL);
}
-
+
if (op->agent != NULL) {
- set_ocf_env("OCF_RESOURCE_TYPE", op->agent, NULL);
+ set_ocf_env("OCF_RESOURCE_TYPE", op->agent, NULL);
}
/* Notes: this is not added to specification yet. Sept 10,2004 */
if (op->provider != NULL) {
- set_ocf_env("OCF_RESOURCE_PROVIDER", op->provider, NULL);
+ set_ocf_env("OCF_RESOURCE_PROVIDER", op->provider, NULL);
}
}
@@ -167,7 +167,7 @@ static gboolean recurring_action_timer(gpointer data)
/* Clean out the old result */
free(op->stdout_data); op->stdout_data = NULL;
free(op->stderr_data); op->stderr_data = NULL;
-
+
services_action_async(op, NULL);
return FALSE;
}
@@ -184,59 +184,59 @@ operation_finished(mainloop_child_t *p, int status, int signo, int
exitcode)
MH_ASSERT(op->pid == p->pid);
if( signo ) {
- if( p->timeout ) {
- mh_warn("%s:%d - timed out after %dms", op->id, op->pid,
op->timeout);
- op->status = LRM_OP_TIMEOUT;
+ if( p->timeout ) {
+ mh_warn("%s:%d - timed out after %dms", op->id, op->pid,
op->timeout);
+ op->status = LRM_OP_TIMEOUT;
- } else {
- mh_warn("%s:%d - terminated with signal %d", op->id, op->pid,
signo);
- op->status = LRM_OP_ERROR;
- }
+ } else {
+ mh_warn("%s:%d - terminated with signal %d", op->id,
op->pid, signo);
+ op->status = LRM_OP_ERROR;
+ }
} else {
- op->rc = exitcode;
- mh_debug("%s:%d - exited with rc=%d", op->id, op->pid,
exitcode);
-
- if(op->stdout_data) {
- next = op->stdout_data;
- do {
- offset = next;
- next = strchrnul(offset, '\n');
- mh_debug("%s:%d [ %.*s ]", op->id, op->pid,
(int)(next-offset), offset);
- if(next[0] != 0) {
- next++;
- }
-
- } while(next != NULL && next[0] != 0);
- }
-
- if(op->stderr_data) {
- next = op->stderr_data;
- do {
- offset = next;
- next = strchrnul(offset, '\n');
- mh_notice("%s:%d [ %.*s ]", op->id, op->pid,
(int)(next-offset), offset);
- if(next[0] != 0) {
- next++;
- }
-
- } while(next != NULL && next[0] != 0);
- }
+ op->rc = exitcode;
+ mh_debug("%s:%d - exited with rc=%d", op->id, op->pid,
exitcode);
+
+ if(op->stdout_data) {
+ next = op->stdout_data;
+ do {
+ offset = next;
+ next = strchrnul(offset, '\n');
+ mh_debug("%s:%d [ %.*s ]", op->id, op->pid,
(int)(next-offset), offset);
+ if(next[0] != 0) {
+ next++;
+ }
+
+ } while(next != NULL && next[0] != 0);
+ }
+
+ if(op->stderr_data) {
+ next = op->stderr_data;
+ do {
+ offset = next;
+ next = strchrnul(offset, '\n');
+ mh_notice("%s:%d [ %.*s ]", op->id, op->pid,
(int)(next-offset), offset);
+ if(next[0] != 0) {
+ next++;
+ }
+
+ } while(next != NULL && next[0] != 0);
+ }
}
-
+
if(op->interval && op->opaque->cancel == FALSE) {
- op->opaque->repeat_timer = g_timeout_add(op->interval,
recurring_action_timer, (void*)op);
+ op->opaque->repeat_timer = g_timeout_add(op->interval,
recurring_action_timer, (void*)op);
}
op->pid = 0;
if(op->opaque->callback) {
- /* Callback might call cancel which would result in the message being free'd
- * Do not access 'op' after this line
- */
- op->opaque->callback(op);
+ /* Callback might call cancel which would result in the message being
free'd
+ * Do not access 'op' after this line
+ */
+ op->opaque->callback(op);
} else if(op->opaque->repeat_timer == 0) {
- services_action_free(op);
+ services_action_free(op);
}
}
@@ -248,68 +248,68 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
int stderr_fd[2];
if ( pipe(stdout_fd) < 0 ) {
- mh_perror(LOG_ERR, "pipe() failed");
+ mh_perror(LOG_ERR, "pipe() failed");
}
if ( pipe(stderr_fd) < 0 ) {
- mh_perror(LOG_ERR, "pipe() failed");
+ mh_perror(LOG_ERR, "pipe() failed");
}
op->pid = fork();
switch(op->pid) {
- case -1:
- mh_perror(LOG_ERR, "fork() failed");
- close(stdout_fd[0]);
- close(stdout_fd[1]);
- close(stderr_fd[0]);
- close(stderr_fd[1]);
- return FALSE;
-
- case 0: /* Child */
- /* Man: The call setpgrp() is equivalent to setpgid(0,0)
- * _and_ compiles on BSD variants too
- * need to investigate if it works the same too.
- */
- setpgid(0,0);
- close(stdout_fd[0]);
- close(stderr_fd[0]);
- if (STDOUT_FILENO != stdout_fd[1]) {
- if (dup2(stdout_fd[1], STDOUT_FILENO)!=STDOUT_FILENO) {
- mh_perror(LOG_ERR, "dup2() failed (stdout)");
- }
- close(stdout_fd[1]);
- }
- if (STDERR_FILENO != stderr_fd[1]) {
- if (dup2(stderr_fd[1], STDERR_FILENO)!=STDERR_FILENO) {
- mh_perror(LOG_ERR, "dup2() failed (stderr)");
- }
- close(stderr_fd[1]);
- }
-
- /* close all descriptors except stdin/out/err and channels to logd */
- for (lpc = getdtablesize() - 1; lpc > STDERR_FILENO; lpc--) {
- close(lpc);
- }
-
- /* Setup environment correctly */
- add_OCF_env_vars(op);
-
- /* execute the RA */
- execvp(op->opaque->exec, op->opaque->args);
-
- switch (errno) { /* see execve(2) */
- case ENOENT: /* No such file or directory */
- case EISDIR: /* Is a directory */
- rc = OCF_NOT_INSTALLED;
- break;
- case EACCES: /* permission denied (various errors) */
- rc = OCF_INSUFFICIENT_PRIV;
- break;
- default:
- rc = OCF_UNKNOWN_ERROR;
- break;
- }
- _exit(rc);
+ case -1:
+ mh_perror(LOG_ERR, "fork() failed");
+ close(stdout_fd[0]);
+ close(stdout_fd[1]);
+ close(stderr_fd[0]);
+ close(stderr_fd[1]);
+ return FALSE;
+
+ case 0: /* Child */
+ /* Man: The call setpgrp() is equivalent to setpgid(0,0)
+ * _and_ compiles on BSD variants too
+ * need to investigate if it works the same too.
+ */
+ setpgid(0,0);
+ close(stdout_fd[0]);
+ close(stderr_fd[0]);
+ if (STDOUT_FILENO != stdout_fd[1]) {
+ if (dup2(stdout_fd[1], STDOUT_FILENO)!=STDOUT_FILENO) {
+ mh_perror(LOG_ERR, "dup2() failed (stdout)");
+ }
+ close(stdout_fd[1]);
+ }
+ if (STDERR_FILENO != stderr_fd[1]) {
+ if (dup2(stderr_fd[1], STDERR_FILENO)!=STDERR_FILENO) {
+ mh_perror(LOG_ERR, "dup2() failed (stderr)");
+ }
+ close(stderr_fd[1]);
+ }
+
+ /* close all descriptors except stdin/out/err and channels to logd */
+ for (lpc = getdtablesize() - 1; lpc > STDERR_FILENO; lpc--) {
+ close(lpc);
+ }
+
+ /* Setup environment correctly */
+ add_OCF_env_vars(op);
+
+ /* execute the RA */
+ execvp(op->opaque->exec, op->opaque->args);
+
+ switch (errno) { /* see execve(2) */
+ case ENOENT: /* No such file or directory */
+ case EISDIR: /* Is a directory */
+ rc = OCF_NOT_INSTALLED;
+ break;
+ case EACCES: /* permission denied (various errors) */
+ rc = OCF_INSUFFICIENT_PRIV;
+ break;
+ default:
+ rc = OCF_UNKNOWN_ERROR;
+ break;
+ }
+ _exit(rc);
}
/* Only the parent reaches here */
@@ -323,55 +323,55 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
set_fd_opts(op->opaque->stderr_fd, O_NONBLOCK);
if(synchronous) {
- int status = 0;
- int timeout = 1 + op->timeout / 1000;
- mh_trace("Waiting for %d", op->pid);
- while(timeout > 0 && waitpid(op->pid, &status, WNOHANG) <=
0) {
- sleep(1);
- timeout--;
- }
-
- mh_trace("Child done: %d", op->pid);
- if(timeout == 0) {
- int killrc = sigar_proc_kill(op->pid, 9 /*SIGKILL*/);
-
- op->status = LRM_OP_TIMEOUT;
- mh_warn("%s:%d - timed out after %dms", op->id, op->pid,
op->timeout);
-
- if (killrc != SIGAR_OK && killrc != ESRCH) {
- mh_err("kill(%d, KILL) failed: %d", op->pid, killrc);
- }
-
- } else if (WIFEXITED(status)) {
- op->status = LRM_OP_DONE;
- op->rc = WEXITSTATUS(status);
- mh_err("Managed %s process %d exited with rc=%d", op->id,
op->pid, op->rc);
-
- } else if (WIFSIGNALED(status)) {
- int signo = WTERMSIG(status);
- op->status = LRM_OP_ERROR;
- mh_err("Managed %s process %d exited with signal=%d", op->id,
op->pid, signo);
- }
+ int status = 0;
+ int timeout = 1 + op->timeout / 1000;
+ mh_trace("Waiting for %d", op->pid);
+ while(timeout > 0 && waitpid(op->pid, &status, WNOHANG) <=
0) {
+ sleep(1);
+ timeout--;
+ }
+
+ mh_trace("Child done: %d", op->pid);
+ if(timeout == 0) {
+ int killrc = sigar_proc_kill(op->pid, 9 /*SIGKILL*/);
+
+ op->status = LRM_OP_TIMEOUT;
+ mh_warn("%s:%d - timed out after %dms", op->id, op->pid,
op->timeout);
+
+ if (killrc != SIGAR_OK && killrc != ESRCH) {
+ mh_err("kill(%d, KILL) failed: %d", op->pid, killrc);
+ }
+
+ } else if (WIFEXITED(status)) {
+ op->status = LRM_OP_DONE;
+ op->rc = WEXITSTATUS(status);
+ mh_err("Managed %s process %d exited with rc=%d", op->id,
op->pid, op->rc);
+
+ } else if (WIFSIGNALED(status)) {
+ int signo = WTERMSIG(status);
+ op->status = LRM_OP_ERROR;
+ mh_err("Managed %s process %d exited with signal=%d", op->id,
op->pid, signo);
+ }
#ifdef WCOREDUMP
- if (WCOREDUMP(status)) {
- mh_err("Managed %s process %d dumped core", op->id,
op->pid);
- }
+ if (WCOREDUMP(status)) {
+ mh_err("Managed %s process %d dumped core", op->id,
op->pid);
+ }
#endif
-
- read_output(op->opaque->stdout_fd, op);
- read_output(op->opaque->stderr_fd, op);
-
+
+ read_output(op->opaque->stdout_fd, op);
+ read_output(op->opaque->stderr_fd, op);
+
} else {
- mh_trace("Async waiting for %d - %s", op->pid,
op->opaque->exec);
- mainloop_add_child(op->pid, op->timeout, op->id, op,
operation_finished);
+ mh_trace("Async waiting for %d - %s", op->pid,
op->opaque->exec);
+ mainloop_add_child(op->pid, op->timeout, op->id, op,
operation_finished);
- op->opaque->stdout_gsource = mainloop_add_fd(
- G_PRIORITY_LOW, op->opaque->stdout_fd, read_output, pipe_out_done,
op);
+ op->opaque->stdout_gsource = mainloop_add_fd(
+ G_PRIORITY_LOW, op->opaque->stdout_fd, read_output, pipe_out_done,
op);
- op->opaque->stderr_gsource = mainloop_add_fd(
- G_PRIORITY_LOW, op->opaque->stderr_fd, read_output, pipe_err_done,
op);
+ op->opaque->stderr_gsource = mainloop_add_fd(
+ G_PRIORITY_LOW, op->opaque->stderr_fd, read_output, pipe_err_done,
op);
}
-
+
return TRUE;
}
@@ -386,41 +386,41 @@ services_os_get_directory_list(const char *root, gboolean files)
entries = scandir(root, &namelist, NULL, alphasort);
if (entries <= 0) {
- return list;
+ return list;
}
-
+
for (lpc = 0; lpc < entries; lpc++) {
- struct stat sb;
- if ('.' == namelist[lpc]->d_name[0]) {
- free(namelist[lpc]);
- continue;
- }
-
- snprintf(buffer, FILENAME_MAX, "%s/%s", root,
namelist[lpc]->d_name);
-
- stat(buffer, &sb);
- if(S_ISDIR(sb.st_mode)) {
- if(files) {
- free(namelist[lpc]);
- continue;
- }
-
- } else if(S_ISREG(sb.st_mode)) {
- if(files == FALSE) {
- free(namelist[lpc]);
- continue;
-
- } else if( (sb.st_mode & S_IXUSR) == 0
- && (sb.st_mode & S_IXGRP) == 0
- && (sb.st_mode & S_IXOTH) == 0 ) {
- free(namelist[lpc]);
- continue;
- }
- }
-
- list = g_list_append(list, namelist[lpc]->d_name);
+ struct stat sb;
+ if ('.' == namelist[lpc]->d_name[0]) {
+ free(namelist[lpc]);
+ continue;
+ }
+
+ snprintf(buffer, FILENAME_MAX, "%s/%s", root,
namelist[lpc]->d_name);
+
+ stat(buffer, &sb);
+ if(S_ISDIR(sb.st_mode)) {
+ if(files) {
+ free(namelist[lpc]);
+ continue;
+ }
+
+ } else if(S_ISREG(sb.st_mode)) {
+ if(files == FALSE) {
+ free(namelist[lpc]);
+ continue;
+
+ } else if( (sb.st_mode & S_IXUSR) == 0
+ && (sb.st_mode & S_IXGRP) == 0
+ && (sb.st_mode & S_IXOTH) == 0 ) {
+ free(namelist[lpc]);
+ continue;
+ }
+ }
+
+ list = g_list_append(list, namelist[lpc]->d_name);
}
-
+
free(namelist);
#endif
return list;
@@ -430,45 +430,45 @@ void
services_os_set_exec(svc_action_t* op)
{
if(strcmp("enable", op->action) == 0) {
- op->opaque->exec = strdup("/sbin/chkconfig");
- op->opaque->args[0] = strdup(op->opaque->exec);
- op->opaque->args[1] = strdup(op->agent);
- op->opaque->args[2] = strdup("on");
- op->opaque->args[3] = NULL;
-
+ op->opaque->exec = strdup("/sbin/chkconfig");
+ op->opaque->args[0] = strdup(op->opaque->exec);
+ op->opaque->args[1] = strdup(op->agent);
+ op->opaque->args[2] = strdup("on");
+ op->opaque->args[3] = NULL;
+
} else if(strcmp("disable", op->action) == 0) {
- op->opaque->exec = strdup("/sbin/chkconfig");
- op->opaque->args[0] = strdup(op->opaque->exec);
- op->opaque->args[1] = strdup(op->agent);
- op->opaque->args[2] = strdup("off");
- op->opaque->args[3] = NULL;
+ op->opaque->exec = strdup("/sbin/chkconfig");
+ op->opaque->args[0] = strdup(op->opaque->exec);
+ op->opaque->args[1] = strdup(op->agent);
+ op->opaque->args[2] = strdup("off");
+ op->opaque->args[3] = NULL;
} else {
- op->opaque->exec = malloc(500);
- snprintf(op->opaque->exec, 500, "%s/%s", LSB_ROOT,
op->agent);
- op->opaque->args[0] = strdup(op->opaque->exec);
- op->opaque->args[1] = strdup(op->action);
- op->opaque->args[2] = NULL;
+ op->opaque->exec = malloc(500);
+ snprintf(op->opaque->exec, 500, "%s/%s", LSB_ROOT,
op->agent);
+ op->opaque->args[0] = strdup(op->opaque->exec);
+ op->opaque->args[1] = strdup(op->action);
+ op->opaque->args[2] = NULL;
}
}
-GList *services_os_list(void)
+GList *services_os_list(void)
{
return get_directory_list(LSB_ROOT, TRUE);
}
-GList *resources_os_list_ocf_providers(void)
+GList *resources_os_list_ocf_providers(void)
{
return get_directory_list(OCF_ROOT"/resource.d", FALSE);
}
-GList *resources_os_list_ocf_agents(const char *provider)
+GList *resources_os_list_ocf_agents(const char *provider)
{
if(provider) {
- char buffer[500];
- snprintf(buffer, 500, "%s//resource.d/%s", OCF_ROOT, provider);
- return get_directory_list(buffer, TRUE);
+ char buffer[500];
+ snprintf(buffer, 500, "%s//resource.d/%s", OCF_ROOT, provider);
+ return get_directory_list(buffer, TRUE);
}
return NULL;
}
--
1.7.4.4
_______________________________________________
Matahari mailing list
Matahari(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/matahari