mirror of
https://github.com/samba-team/samba.git
synced 2025-03-27 22:50:26 +03:00
ctdb-common: New function ctdb_set_helper()
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
This commit is contained in:
parent
c6cb2d6508
commit
89b08c0f0b
@ -64,6 +64,66 @@ void ctdb_die(struct ctdb_context *ctdb, const char *msg)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Set the path of a helper program from envvar, falling back to
|
||||
* dir/file if envvar unset. type is a string to print in log
|
||||
* messages. helper is assumed to point to a statically allocated
|
||||
* array of size bytes, initialised to "". If file is NULL don't fall
|
||||
* back if envvar is unset. If dir is NULL and envvar is unset (but
|
||||
* file is not NULL) then this is an error. Returns true if helper is
|
||||
* set, either previously or this time. */
|
||||
bool ctdb_set_helper(const char *type, char *helper, size_t size,
|
||||
const char *envvar,
|
||||
const char *dir, const char *file)
|
||||
{
|
||||
const char *t;
|
||||
struct stat st;
|
||||
|
||||
if (helper[0] != '\0') {
|
||||
/* Already set */
|
||||
return true;
|
||||
}
|
||||
|
||||
t = getenv(envvar);
|
||||
if (t != NULL) {
|
||||
if (strlen(t) >= size) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Unable to set %s - path too long\n", type));
|
||||
return false;
|
||||
}
|
||||
|
||||
strncpy(helper, t, size);
|
||||
} else if (file == NULL) {
|
||||
return false;
|
||||
} else if (dir == NULL) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Unable to set %s - dir is NULL\n", type));
|
||||
return false;
|
||||
} else {
|
||||
if (snprintf(helper, size, "%s/%s", dir, file) >= size) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Unable to set %s - path too long\n", type));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (stat(helper, &st) != 0) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Unable to set %s \"%s\" - %s\n",
|
||||
type, helper, strerror(errno)));
|
||||
return false;
|
||||
}
|
||||
if (!(st.st_mode & S_IXUSR)) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Unable to set %s \"%s\" - not executable\n",
|
||||
type, helper));
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG(DEBUG_NOTICE,
|
||||
("Set %s to \"%s\"\n", type, helper));
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Invoke an external program to do some sort of tracing on the CTDB
|
||||
* process. This might block for a little while. The external
|
||||
* program is specified by the environment variable
|
||||
|
@ -722,6 +722,8 @@ struct ctdb_fetch_handle {
|
||||
void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
|
||||
void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
|
||||
void ctdb_die(struct ctdb_context *ctdb, const char *msg);
|
||||
bool ctdb_set_helper(const char *type, char *helper, size_t size,
|
||||
const char *envvar, const char *dir, const char *file);
|
||||
void ctdb_external_trace(void);
|
||||
bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
|
||||
int ctdb_parse_address(struct ctdb_context *ctdb,
|
||||
|
Loading…
x
Reference in New Issue
Block a user