summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
0229d75)
The next step towards sideband connections is to send the output of
each command as a sideband packet. To this aim, afs_cb_result_handler(),
pass_buffer_as_shm() and the callback_result_handler typedef are modified
to receive an additional "band" parameter.
For regular command output the value of this parameter is SBD_OUTPUT,
the sideband designator for normal output. The client code is patched
to add the contents of received SBD_OUTPUT sidband packets to the
buffer tree for the normal ouput.
However, log messages, which are only written to the log output
of the server at the moment, may also passed to the client via the
SBD_XXX_LOG designators, where XXX is the name of one of the usual
log levels for para_log().
The patch contains quite a few changes of the form
if (use_sideband)
do_new_stuff()
else
do_it_as_before()
which is a bit ugly, but we may remove the old method in 0.5.0,
which will support only sideband connections.
struct callback_result {
/** The number of bytes of the result. */
size_t result_size;
struct callback_result {
/** The number of bytes of the result. */
size_t result_size;
+ /** The band designator (loglevel for the result). */
+ uint8_t band;
};
static int dispatch_result(int result_shmid, callback_result_handler *handler,
};
static int dispatch_result(int result_shmid, callback_result_handler *handler,
{
struct osl_object result;
void *result_shm;
{
struct osl_object result;
void *result_shm;
- int ret2, ret = shm_attach(result_shmid, ATTACH_RO, &result_shm);
+ /* must attach r/w as result.data might get encrypted in-place. */
+ int ret2, ret = shm_attach(result_shmid, ATTACH_RW, &result_shm);
struct callback_result *cr = result_shm;
if (ret < 0) {
struct callback_result *cr = result_shm;
if (ret < 0) {
result.data = result_shm + sizeof(*cr);
if (result.size) {
assert(handler);
result.data = result_shm + sizeof(*cr);
if (result.size) {
assert(handler);
- ret = handler(&result, private_result_data);
+ ret = handler(&result, cr->band, private_result_data);
if (ret < 0)
PARA_NOTICE_LOG("result handler error: %s\n",
para_strerror(-ret));
if (ret < 0)
PARA_NOTICE_LOG("result handler error: %s\n",
para_strerror(-ret));
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
},
.max_size_handler = afs_max_size_handler,
};
},
.max_size_handler = afs_max_size_handler,
};
current_mop : "dummy mood", num_admissible);
out:
if (ret2 >= 0 && pb.offset)
current_mop : "dummy mood", num_admissible);
out:
if (ret2 >= 0 && pb.offset)
- pass_buffer_as_shm(fd, pb.buf, pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
* Result handler for sending data to the para_client process.
*
* \param result The data to be sent.
* Result handler for sending data to the para_client process.
*
* \param result The data to be sent.
- * \param private Pointer to the context.
+ * \param band The band designator.
+ * \param private Pointer to the command context.
- * \return The return value of the underlying call to sc_send_bin_buffer().
+ * \return The return value of the underlying call to \ref command.c::send_sb.
- * \sa \ref callback_result_handler, \ref sc_send_bin_buffer().
+ * \sa \ref callback_result_handler, \ref command.c::send_sb.
-int afs_cb_result_handler(struct osl_object *result, void *private)
+int afs_cb_result_handler(struct osl_object *result, uint8_t band,
+ void *private)
{
struct command_context *cc = private;
{
struct command_context *cc = private;
if (!result->size)
return 1;
if (!result->size)
return 1;
- ret = sc_send_bin_buffer(&cc->scc, result->data, result->size);
- if (ret < 0 || ret == result->size)
- return ret;
- return -E_SHORT_WRITE;
+ if (cc->use_sideband)
+ return send_sb(&cc->scc, result->data, result->size, band,
+ true);
+ return sc_send_bin_buffer(&cc->scc, result->data, result->size);
}
int com_select(struct command_context *cc)
}
int com_select(struct command_context *cc)
* Send data as shared memory to a file descriptor.
*
* \param fd File descriptor to send the shmid to.
* Send data as shared memory to a file descriptor.
*
* \param fd File descriptor to send the shmid to.
+ * \param band The band designator for this data.
* \param buf The buffer holding the data to be sent.
* \param size The size of \a buf.
*
* \param buf The buffer holding the data to be sent.
* \param size The size of \a buf.
*
* \return Zero if \a buf is \p NULL or \a size is zero. Negative on errors,
* and positive on success.
*/
* \return Zero if \a buf is \p NULL or \a size is zero. Negative on errors,
* and positive on success.
*/
-int pass_buffer_as_shm(int fd, char *buf, size_t size)
+int pass_buffer_as_shm(int fd, uint8_t band, char *buf, size_t size)
{
int ret, shmid;
void *shm;
{
int ret, shmid;
void *shm;
if (!buf || !size)
return 0;
if (!buf || !size)
return 0;
- ret = shm_new(size + sizeof(struct callback_result));
+ ret = shm_new(size + sizeof(*cr));
if (ret < 0)
return ret;
shmid = ret;
if (ret < 0)
return ret;
shmid = ret;
goto err;
cr = shm;
cr->result_size = size;
goto err;
cr = shm;
cr->result_size = size;
memcpy(shm + sizeof(*cr), buf, size);
ret = shm_detach(shm);
if (ret < 0)
memcpy(shm + sizeof(*cr), buf, size);
ret = shm_detach(shm);
if (ret < 0)
if (ret < 0)
para_printf(&pb, "%s\n", para_strerror(-ret));
if (pb.buf)
if (ret < 0)
para_printf(&pb, "%s\n", para_strerror(-ret));
if (pb.buf)
- pass_buffer_as_shm(fd, pb.buf, pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
*
* \sa \ref send_callback_request().
*/
*
* \sa \ref send_callback_request().
*/
-typedef int callback_result_handler(struct osl_object *result, void *private);
-int afs_cb_result_handler(struct osl_object *result, void *private);
-int pass_buffer_as_shm(int fd, char *buf, size_t size);
+typedef int callback_result_handler(struct osl_object *result, uint8_t band, void *private);
+int afs_cb_result_handler(struct osl_object *result, uint8_t band, void *private);
+int pass_buffer_as_shm(int fd, uint8_t band, char *buf, size_t size);
/** Structure passed to the AFS max_size handler. */
struct afs_max_size_handler_data {
/** Local socket connecting the command handler and the AFS process. */
int fd;
/** Structure passed to the AFS max_size handler. */
struct afs_max_size_handler_data {
/** Local socket connecting the command handler and the AFS process. */
int fd;
+ /** The sideband designator for this data packet. */
+ uint8_t band;
_static_inline_ int afs_max_size_handler(char *buf, size_t size, void *private)
{
struct afs_max_size_handler_data *amshd = private;
_static_inline_ int afs_max_size_handler(char *buf, size_t size, void *private)
{
struct afs_max_size_handler_data *amshd = private;
- return pass_buffer_as_shm(amshd->fd, buf, size);
+ return pass_buffer_as_shm(amshd->fd, amshd->band, buf, size);
}
__noreturn void afs_init(uint32_t cookie, int socket_fd);
}
__noreturn void afs_init(uint32_t cookie, int socket_fd);
.max_size_handler = afs_max_size_handler,
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size_handler = afs_max_size_handler,
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
- pass_buffer_as_shm(fd, b.buf, b.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, b.buf, b.offset);
free(b.buf);
free(opts->data);
free(opts->data_ptr);
free(b.buf);
free(opts->data);
free(opts->data_ptr);
.max_size_handler = afs_max_size_handler,
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size_handler = afs_max_size_handler,
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
}
};
uint16_t afhi_offset, chunks_offset;
}
};
uint16_t afhi_offset, chunks_offset;
if (ret < 0)
para_printf(&msg, "%s\n", para_strerror(-ret));
if (msg.offset)
if (ret < 0)
para_printf(&msg, "%s\n", para_strerror(-ret));
if (msg.offset)
- pass_buffer_as_shm(fd, msg.buf, msg.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, msg.buf, msg.offset);
int ret = aft_get_row_of_path(path, &path_brother);
if (ret < 0)
return;
int ret = aft_get_row_of_path(path, &path_brother);
if (ret < 0)
return;
- pass_buffer_as_shm(fd, (char *)&path_brother, sizeof(path_brother));
+ pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&path_brother,
+ sizeof(path_brother));
}
static void hash_sister_callback(int fd, const struct osl_object *query)
}
static void hash_sister_callback(int fd, const struct osl_object *query)
hash_sister = find_hash_sister(hash);
if (!hash_sister)
return;
hash_sister = find_hash_sister(hash);
if (!hash_sister)
return;
- pass_buffer_as_shm(fd, (char *)&hash_sister, sizeof(hash_sister));
+ pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&hash_sister,
+ sizeof(hash_sister));
-static int get_row_pointer_from_result(struct osl_object *result, void *private)
+static int get_row_pointer_from_result(struct osl_object *result,
+ __a_unused uint8_t band, void *private)
{
struct osl_row **row = private;
*row = *(struct osl_row **)(result->data);
{
struct osl_row **row = private;
*row = *(struct osl_row **)(result->data);
ret = 1;
if (pb && (pad->flags & ADD_FLAG_LAZY)) { /* lazy is really cheap */
if (pad->flags & ADD_FLAG_VERBOSE)
ret = 1;
if (pb && (pad->flags & ADD_FLAG_LAZY)) { /* lazy is really cheap */
if (pad->flags & ADD_FLAG_VERBOSE)
- send_ret = sc_send_va_buffer(&pad->cc->scc,
- "lazy-ignore: %s\n", path);
+ send_ret = pad->cc->use_sideband?
+ send_sb_va(&pad->cc->scc, SBD_OUTPUT,
+ "lazy-ignore: %s\n", path)
+ :
+ sc_send_va_buffer(&pad->cc->scc,
+ "lazy-ignore: %s\n", path);
goto out_free;
}
/* We still want to add this file. Compute its hash. */
goto out_free;
}
/* We still want to add this file. Compute its hash. */
ret = 1;
if (pb && hs && hs == pb && !(pad->flags & ADD_FLAG_FORCE)) {
if (pad->flags & ADD_FLAG_VERBOSE)
ret = 1;
if (pb && hs && hs == pb && !(pad->flags & ADD_FLAG_FORCE)) {
if (pad->flags & ADD_FLAG_VERBOSE)
- send_ret = sc_send_va_buffer(&pad->cc->scc,
- "%s exists, not forcing update\n", path);
+ send_ret = pad->cc->use_sideband?
+ send_sb_va(&pad->cc->scc, SBD_OUTPUT,
+ "%s exists, not forcing update\n", path)
+ :
+ sc_send_va_buffer(&pad->cc->scc,
+ "%s exists, not forcing update\n", path);
munmap(map.data, map.size);
close(fd);
if (pad->flags & ADD_FLAG_VERBOSE) {
munmap(map.data, map.size);
close(fd);
if (pad->flags & ADD_FLAG_VERBOSE) {
- send_ret = sc_send_va_buffer(&pad->cc->scc, "adding %s\n", path);
+ send_ret = pad->cc->use_sideband?
+ send_sb_va(&pad->cc->scc, SBD_OUTPUT,
+ "adding %s\n", path)
+ :
+ sc_send_va_buffer(&pad->cc->scc,
+ "adding %s\n", path);
if (send_ret < 0)
goto out_free;
}
if (send_ret < 0)
goto out_free;
}
munmap(map.data, map.size);
out_free:
if (ret < 0 && send_ret >= 0)
munmap(map.data, map.size);
out_free:
if (ret < 0 && send_ret >= 0)
- send_ret = sc_send_va_buffer(&pad->cc->scc,
- "failed to add %s (%s)\n", path, para_strerror(-ret));
+ send_ret = pad->cc->use_sideband?
+ send_sb_va(&pad->cc->scc, SBD_ERROR_LOG,
+ "failed to add %s (%s)\n", path,
+ para_strerror(-ret))
+ :
+ sc_send_va_buffer(&pad->cc->scc,
+ "failed to add %s (%s)\n", path,
+ para_strerror(-ret));
free(obj.data);
clear_afhi(afhi_ptr);
/* Stop adding files only on send errors. */
free(obj.data);
clear_afhi(afhi_ptr);
/* Stop adding files only on send errors. */
char *path;
ret = verify_path(cc->argv[i], &path);
if (ret < 0) {
char *path;
ret = verify_path(cc->argv[i], &path);
if (ret < 0) {
- ret = sc_send_va_buffer(&cc->scc, "%s: %s\n",
+ ret = cc->use_sideband?
+ send_sb_va(&cc->scc, SBD_ERROR_LOG, "%s: %s\n",
+ cc->argv[i], para_strerror(-ret))
+ :
+ sc_send_va_buffer(&cc->scc, "%s: %s\n",
cc->argv[i], para_strerror(-ret));
if (ret < 0)
return ret;
cc->argv[i], para_strerror(-ret));
if (ret < 0)
return ret;
}
ret = stat(path, &statbuf);
if (ret < 0) {
}
ret = stat(path, &statbuf);
if (ret < 0) {
- ret = sc_send_va_buffer(&cc->scc,
- "failed to stat %s (%s)\n", path,
- strerror(errno));
+ ret = cc->use_sideband?
+ send_sb_va(&cc->scc, SBD_ERROR_LOG,
+ "failed to stat %s (%s)\n", path,
+ strerror(errno))
+ :
+ sc_send_va_buffer(&cc->scc,
+ "failed to stat %s (%s)\n", path,
+ strerror(errno));
free(path);
if (ret < 0)
return ret;
free(path);
if (ret < 0)
return ret;
else
ret = add_one_audio_file(path, &pad);
if (ret < 0) {
else
ret = add_one_audio_file(path, &pad);
if (ret < 0) {
- sc_send_va_buffer(&cc->scc, "%s: %s\n", path,
- para_strerror(-ret));
+ if (cc->use_sideband)
+ send_sb_va(&cc->scc, SBD_OUTPUT, "%s: %s\n", path,
+ para_strerror(-ret));
+ else
+ sc_send_va_buffer(&cc->scc, "%s: %s\n", path,
+ para_strerror(-ret));
free(path);
return ret;
}
free(path);
return ret;
}
else if (pmd.num_matches == 0)
ret2 = para_printf(&tad.pb, "no matches\n");
if (ret2 >= 0 && tad.pb.offset)
else if (pmd.num_matches == 0)
ret2 = para_printf(&tad.pb, "no matches\n");
if (ret2 >= 0 && tad.pb.offset)
- pass_buffer_as_shm(fd, tad.pb.buf, tad.pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, tad.pb.buf, tad.pb.offset);
pmd.num_matches);
}
if (ret >= 0 && crd.pb.offset)
pmd.num_matches);
}
if (ret >= 0 && crd.pb.offset)
- pass_buffer_as_shm(fd, crd.pb.buf, crd.pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, crd.pb.buf, crd.pb.offset);
para_printf(&cad.pb, "nothing copied\n");
}
if (cad.pb.offset)
para_printf(&cad.pb, "nothing copied\n");
}
if (cad.pb.offset)
- pass_buffer_as_shm(fd, cad.pb.buf, cad.pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, cad.pb.buf, cad.pb.offset);
- pass_buffer_as_shm(fd, buf, strlen(buf));
+ pass_buffer_as_shm(fd, SBD_OUTPUT, buf, strlen(buf));
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
},
.max_size_handler = afs_max_size_handler
};
},
.max_size_handler = afs_max_size_handler
};
return;
audio_file_loop(&pb, check_audio_file);
if (pb.offset)
return;
audio_file_loop(&pb, check_audio_file);
if (pb.offset)
- pass_buffer_as_shm(fd, pb.buf, pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
},
.max_size_handler = afs_max_size_handler
}
},
.max_size_handler = afs_max_size_handler
}
pmd.pm_flags |= PM_REVERSE_LOOP;
for_each_matching_row(&pmd);
if (laad.pb.offset)
pmd.pm_flags |= PM_REVERSE_LOOP;
for_each_matching_row(&pmd);
if (laad.pb.offset)
- pass_buffer_as_shm(fd, laad.pb.buf, laad.pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, laad.pb.buf, laad.pb.offset);
}
ret = send_option_arg_callback_request(&options, cc->argc - i, cc->argv + i,
com_lsatt_callback, afs_cb_result_handler, cc);
}
ret = send_option_arg_callback_request(&options, cc->argc - i, cc->argv + i,
com_lsatt_callback, afs_cb_result_handler, cc);
-
- if (!ret) {
- if (cc->argc > 1)
- ret = sc_send_va_buffer(&cc->scc, "no matches\n");
- } else if (ret < 0)
+ else if (ret == 0 && cc->argc > 1)
+ ret = cc->use_sideband?
+ send_sb_va(&cc->scc, SBD_ERROR_LOG, "no matches\n")
+ :
+ sc_send_va_buffer(&cc->scc, "no matches\n");
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
},
.max_size_handler = afs_max_size_handler
};
},
.max_size_handler = afs_max_size_handler
};
if (ret < 0 && ret2 >= 0)
para_printf(&pb, "%s: %s\n", p, para_strerror(-ret));
if (pb.offset)
if (ret < 0 && ret2 >= 0)
para_printf(&pb, "%s: %s\n", p, para_strerror(-ret));
if (pb.offset)
- pass_buffer_as_shm(fd, pb.buf, pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
},
.max_size_handler = afs_max_size_handler,
};
},
.max_size_handler = afs_max_size_handler,
};
else
afs_event(ATTRIBUTE_RENAME, &pb, NULL);
if (pb.offset)
else
afs_event(ATTRIBUTE_RENAME, &pb, NULL);
if (pb.offset)
- pass_buffer_as_shm(fd, pb.buf, pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
},
.max_size_handler = afs_max_size_handler,
}
},
.max_size_handler = afs_max_size_handler,
}
else if (!raad.num_removed)
ret2 = para_printf(&raad.pb, "no match -- nothing removed\n");
if (ret2 >= 0 && raad.pb.offset)
else if (!raad.num_removed)
ret2 = para_printf(&raad.pb, "no match -- nothing removed\n");
if (ret2 >= 0 && raad.pb.offset)
- pass_buffer_as_shm(fd, raad.pb.buf, raad.pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, raad.pb.buf, raad.pb.offset);
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
},
.max_size_handler = afs_max_size_handler,
}
},
.max_size_handler = afs_max_size_handler,
}
else if (pmd.num_matches == 0 && pmd.patterns.size > 0)
para_printf(&lbad.pb, "no matches\n");
if (lbad.pb.offset)
else if (pmd.num_matches == 0 && pmd.patterns.size > 0)
para_printf(&lbad.pb, "no matches\n");
if (lbad.pb.offset)
- pass_buffer_as_shm(fd, lbad.pb.buf, lbad.pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, lbad.pb.buf, lbad.pb.offset);
if (ret < 0)
return (ret == osl(-E_OSL_EMPTY))? 0 : ret;
assert(obj.size > 0);
if (ret < 0)
return (ret == osl(-E_OSL_EMPTY))? 0 : ret;
assert(obj.size > 0);
- ret = pass_buffer_as_shm(fd, obj.data, obj.size);
+ ret = pass_buffer_as_shm(fd, SBD_OUTPUT, obj.data, obj.size);
ret2 = osl(osl_close_disk_object(&obj));
return (ret < 0)? ret : ret2;
}
ret2 = osl(osl_close_disk_object(&obj));
return (ret < 0)? ret : ret2;
}
for_each_matching_row(&pmd);
if (pmd.num_matches == 0) {
char err_msg[] = "no matches\n";
for_each_matching_row(&pmd);
if (pmd.num_matches == 0) {
char err_msg[] = "no matches\n";
- pass_buffer_as_shm(fd, err_msg, sizeof(err_msg));
+ pass_buffer_as_shm(fd, SBD_OUTPUT, err_msg, sizeof(err_msg));
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
},
.max_size_handler = afs_max_size_handler,
}
},
.max_size_handler = afs_max_size_handler,
}
}
out:
if (ret2 >= 0 && rmbd.pb.offset)
}
out:
if (ret2 >= 0 && rmbd.pb.offset)
- pass_buffer_as_shm(fd, rmbd.pb.buf, rmbd.pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, rmbd.pb.buf, rmbd.pb.offset);
struct osl_object query, stdin_obj;
int ret;
struct osl_object query, stdin_obj;
int ret;
- ret = sc_send_buffer(&cc->scc, AWAITING_DATA_MSG);
+ if (cc->use_sideband)
+ ret = send_sb(&cc->scc, NULL, 0, SBD_AWAITING_DATA, false);
+ else
+ ret = sc_send_buffer(&cc->scc, AWAITING_DATA_MSG);
if (ret < 0)
return ret;
ret = fd2buf(&cc->scc, max_len, &stdin_obj);
if (ret < 0)
return ret;
ret = fd2buf(&cc->scc, max_len, &stdin_obj);
+static int dispatch_sbb(struct client_task *ct, struct sb_buffer *sbb)
+{
+ int ret, ll;
+
+ if (!sbb || !sbb->iov.iov_base || sbb->iov.iov_len == 0)
+ return 0;
+
+ switch (sbb->band) {
+ case SBD_OUTPUT:
+ btr_add_output(sbb->iov.iov_base, sbb->iov.iov_len, ct->btrn);
+ ret = 1;
+ goto out;
+ case SBD_DEBUG_LOG:
+ case SBD_INFO_LOG:
+ case SBD_NOTICE_LOG:
+ case SBD_WARNING_LOG:
+ case SBD_ERROR_LOG:
+ case SBD_CRIT_LOG:
+ case SBD_EMERG_LOG:
+ ll = sbb->band - SBD_DEBUG_LOG;
+ para_log(ll, "remote: %s", (char *)sbb->iov.iov_base);
+ ret = 1;
+ goto deallocate;
+ default:
+ PARA_ERROR_LOG("invalid band %d\n", sbb->band);
+ ret = -E_BAD_BAND;
+ goto deallocate;
+ }
+deallocate:
+ free(sbb->iov.iov_base);
+out:
+ sbb->iov.iov_base = NULL;
+ return ret;
+}
+
static bool has_feature(const char *feature, struct client_task *ct)
{
return find_arg(feature, ct->features) >= 0? true : false;
static bool has_feature(const char *feature, struct client_task *ct)
{
return find_arg(feature, ct->features) >= 0? true : false;
case CL_SENT_COMMAND:
{
char *buf2;
case CL_SENT_COMMAND:
{
char *buf2;
+ if (ct->use_sideband) {
+ struct sb_buffer sbb;
+ ret = recv_sb(ct, &s->rfds, &sbb);
+ if (ret <= 0)
+ goto out;
+ if (sbb.band == SBD_AWAITING_DATA) {
+ ct->status = CL_SENDING;
+ free(sbb.iov.iov_base);
+ goto out;
+ }
+ ct->status = CL_RECEIVING;
+ ret = dispatch_sbb(ct, &sbb);
+ goto out;
+ }
/* can not use "buf" here because we need a malloced buffer */
buf2 = para_malloc(CLIENT_BUFSIZE);
ret = client_recv_buffer(ct, &s->rfds, buf2, CLIENT_BUFSIZE, &n);
/* can not use "buf" here because we need a malloced buffer */
buf2 = para_malloc(CLIENT_BUFSIZE);
ret = client_recv_buffer(ct, &s->rfds, buf2, CLIENT_BUFSIZE, &n);
*/
if (!FD_ISSET(ct->scc.fd, &s->rfds))
return;
*/
if (!FD_ISSET(ct->scc.fd, &s->rfds))
return;
+ if (ct->use_sideband) {
+ struct sb_buffer sbb;
+ ret = recv_sb(ct, &s->rfds, &sbb);
+ if (ret > 0)
+ ret = dispatch_sbb(ct, &sbb);
+ goto out;
+ }
buf2 = para_malloc(CLIENT_BUFSIZE);
ret = client_recv_buffer(ct, &s->rfds, buf2, CLIENT_BUFSIZE, &n);
if (n > 0) {
buf2 = para_malloc(CLIENT_BUFSIZE);
ret = client_recv_buffer(ct, &s->rfds, buf2, CLIENT_BUFSIZE, &n);
if (n > 0) {
int send_strerror(struct command_context *cc, int err)
{
int send_strerror(struct command_context *cc, int err)
{
- return sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(err));
+ return cc->use_sideband?
+ send_sb_va(&cc->scc, SBD_ERROR_LOG, "%s\n", para_strerror(err))
+ :
+ sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(err));
int com_sender(struct command_context *cc)
{
int com_sender(struct command_context *cc)
{
char *msg = NULL;
struct sender_command_data scd;
if (cc->argc < 2) {
for (i = 0; senders[i].name; i++) {
char *msg = NULL;
struct sender_command_data scd;
if (cc->argc < 2) {
for (i = 0; senders[i].name; i++) {
- char *tmp = make_message("%s%s\n",
- msg? msg : "", senders[i].name);
+ char *tmp;
+ ret = xasprintf(&tmp, "%s%s\n", msg? msg : "",
+ senders[i].name);
+ if (cc->use_sideband)
+ return send_sb(&cc->scc, msg, ret, SBD_OUTPUT, false);
ret = sc_send_buffer(&cc->scc, msg);
free(msg);
return ret;
ret = sc_send_buffer(&cc->scc, msg);
free(msg);
return ret;
if (scd.sender_num < 0)
return ret;
msg = senders[scd.sender_num].help();
if (scd.sender_num < 0)
return ret;
msg = senders[scd.sender_num].help();
+ if (cc->use_sideband)
+ return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT,
+ false);
ret = sc_send_buffer(&cc->scc, msg);
free(msg);
return ret;
ret = sc_send_buffer(&cc->scc, msg);
free(msg);
return ret;
int com_si(struct command_context *cc)
{
int i, ret;
int com_si(struct command_context *cc)
{
int i, ret;
- char *ut;
- char *sender_info = NULL;
+ char *msg, *ut, *sender_info = NULL;
if (cc->argc != 1)
return -E_COMMAND_SYNTAX;
if (cc->argc != 1)
return -E_COMMAND_SYNTAX;
free(info);
}
ut = get_server_uptime_str(now);
free(info);
}
ut = get_server_uptime_str(now);
- ret = sc_send_va_buffer(&cc->scc, "version: " GIT_VERSION "\n"
+ ret = xasprintf(&msg, "version: " GIT_VERSION "\n"
"up: %s\nplayed: %u\n"
"server_pid: %d\n"
"afs_pid: %d\n"
"up: %s\nplayed: %u\n"
"server_pid: %d\n"
"afs_pid: %d\n"
mutex_unlock(mmd_mutex);
free(ut);
free(sender_info);
mutex_unlock(mmd_mutex);
free(ut);
free(sender_info);
+ if (cc->use_sideband)
+ return send_sb(&cc->scc, msg, ret, SBD_OUTPUT, false);
+ ret = sc_send_bin_buffer(&cc->scc, msg, ret);
+ free(msg);
return ret;
}
/* version */
int com_version(struct command_context *cc)
{
return ret;
}
/* version */
int com_version(struct command_context *cc)
{
+ char *msg;
+ size_t len;
+
if (cc->argc != 1)
return -E_COMMAND_SYNTAX;
if (cc->argc != 1)
return -E_COMMAND_SYNTAX;
- return sc_send_buffer(&cc->scc, VERSION_TEXT("server")
- "built: " BUILD_DATE "\n"
- UNAME_RS ", " CC_VERSION "\n"
- );
+ msg = VERSION_TEXT("server") "built: " BUILD_DATE "\n" UNAME_RS
+ ", " CC_VERSION "\n";
+ len = strlen(msg);
+ if (cc->use_sideband)
+ return send_sb(&cc->scc, msg, len, SBD_OUTPUT, true);
+ return sc_send_bin_buffer(&cc->scc, msg, len);
}
#define EMPTY_STATUS_ITEMS \
}
#define EMPTY_STATUS_ITEMS \
*
* This is used by vss when currently no audio file is open.
*/
*
* This is used by vss when currently no audio file is open.
*/
-static char *empty_status_items(int parser_friendly)
+static unsigned empty_status_items(int parser_friendly, char **result)
+ static char *esi;
+ static unsigned len;
+
+ if (esi)
+ goto out;
+
#define ITEM(x) "0004 %02x:\n"
EMPTY_STATUS_ITEMS
#undef ITEM
#define ITEM(x) "0004 %02x:\n"
EMPTY_STATUS_ITEMS
#undef ITEM
EMPTY_STATUS_ITEMS
#undef ITEM
);
EMPTY_STATUS_ITEMS
#undef ITEM
);
- return make_message(
- #define ITEM(x) "%s:\n"
- EMPTY_STATUS_ITEMS
- #undef ITEM
- #define ITEM(x) ,status_item_list[SI_ ## x]
- EMPTY_STATUS_ITEMS
- #undef ITEM
- );
+ else
+ len = xasprintf(&esi,
+ #define ITEM(x) "%s:\n"
+ EMPTY_STATUS_ITEMS
+ #undef ITEM
+ #define ITEM(x) ,status_item_list[SI_ ## x]
+ EMPTY_STATUS_ITEMS
+ #undef ITEM
+ );
+out:
+ *result = esi;
+ return len;
}
#undef EMPTY_STATUS_ITEMS
}
#undef EMPTY_STATUS_ITEMS
{
int i, ret;
struct misc_meta_data tmp, *nmmd = &tmp;
{
int i, ret;
struct misc_meta_data tmp, *nmmd = &tmp;
int32_t num = 0;
int parser_friendly = 0;
int32_t num = 0;
int parser_friendly = 0;
for (;;) {
mmd_dup(nmmd);
ret = get_status(nmmd, parser_friendly, &s);
for (;;) {
mmd_dup(nmmd);
ret = get_status(nmmd, parser_friendly, &s);
- ret = sc_send_bin_buffer(&cc->scc, s, ret);
- free(s);
+ if (cc->use_sideband)
+ ret = send_sb(&cc->scc, s, ret, SBD_OUTPUT, false);
+ else {
+ ret = sc_send_bin_buffer(&cc->scc, s, ret);
+ free(s);
+ }
if (ret < 0)
goto out;
if (nmmd->vss_status_flags & VSS_NEXT) {
if (ret < 0)
goto out;
if (nmmd->vss_status_flags & VSS_NEXT) {
- static char *esi;
- if (!esi)
- esi = empty_status_items(parser_friendly);
- ret = sc_send_buffer(&cc->scc, esi);
+ ret = empty_status_items(parser_friendly, &esi);
+ if (cc->use_sideband)
+ ret = send_sb(&cc->scc, esi, ret, SBD_OUTPUT,
+ true);
+ else
+ ret = sc_send_bin_buffer(&cc->scc, esi, ret);
if (ret < 0)
goto out;
} else
if (ret < 0)
goto out;
} else
if (num > 0 && !--num)
goto out;
sleep(50);
if (num > 0 && !--num)
goto out;
sleep(50);
- return -E_SERVER_CRASH;
-static int send_list_of_commands(struct stream_cipher_context *scc, struct server_command *cmd,
+static int send_list_of_commands(struct command_context *cc, struct server_command *cmd,
+ int ret;
+ char *msg = NULL;
- for (i = 1; cmd->name; cmd++, i++) {
- char *perms = cmd_perms_itohuman(cmd->perms);
- ret = sc_send_va_buffer(scc, "%s\t%s\t%s\t%s\n", cmd->name,
- handler,
- perms,
- cmd->description);
+ for (; cmd->name; cmd++) {
+ char *tmp, *perms = cmd_perms_itohuman(cmd->perms);
+ tmp = make_message("%s\t%s\t%s\t%s\n", cmd->name, handler,
+ perms, cmd->description);
- if (ret < 0)
- return ret;
+ msg = para_strcat(msg, tmp);
+ free(tmp);
+ if (cc->use_sideband)
+ return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false);
+ ret = sc_send_buffer(&cc->scc, msg);
+ free(msg);
+ return ret;
}
/* returns string that must be freed by the caller */
}
/* returns string that must be freed by the caller */
int com_help(struct command_context *cc)
{
struct server_command *cmd;
int com_help(struct command_context *cc)
{
struct server_command *cmd;
+ char *perms, *handler, *buf;
int ret;
if (cc->argc < 2) {
/* no argument given, print list of commands */
int ret;
if (cc->argc < 2) {
/* no argument given, print list of commands */
- if ((ret = send_list_of_commands(&cc->scc, server_cmds, "server")) < 0)
+ if ((ret = send_list_of_commands(cc, server_cmds, "server")) < 0)
- return send_list_of_commands(&cc->scc, afs_cmds, "afs");
+ return send_list_of_commands(cc, afs_cmds, "afs");
}
/* argument given for help */
cmd = get_cmd_ptr(cc->argv[1], &handler);
if (!cmd)
return -E_BAD_CMD;
perms = cmd_perms_itohuman(cmd->perms);
}
/* argument given for help */
cmd = get_cmd_ptr(cc->argv[1], &handler);
if (!cmd)
return -E_BAD_CMD;
perms = cmd_perms_itohuman(cmd->perms);
- ret = sc_send_va_buffer(&cc->scc,
- "%s - %s\n\n"
+ ret = xasprintf(&buf, "%s - %s\n\n"
"handler: %s\n"
"permissions: %s\n"
"usage: %s\n\n"
"handler: %s\n"
"permissions: %s\n"
"usage: %s\n\n"
);
free(perms);
free(handler);
);
free(perms);
free(handler);
+ if (cc->use_sideband)
+ return send_sb(&cc->scc, buf, ret, SBD_OUTPUT, false);
+ ret = sc_send_buffer(&cc->scc, buf);
+ free(buf);
#include "list.h"
#include "ipc.h"
#include "mm.h"
#include "list.h"
#include "ipc.h"
#include "mm.h"
/**
* Contains statistical data of the currently admissible audio files.
/**
* Contains statistical data of the currently admissible audio files.
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
},
.max_size_handler = afs_max_size_handler
};
},
.max_size_handler = afs_max_size_handler
};
osl_rbtree_loop(moods_table, BLOBCOL_ID, &pb,
check_mood);
if (pb.offset)
osl_rbtree_loop(moods_table, BLOBCOL_ID, &pb,
check_mood);
if (pb.offset)
- pass_buffer_as_shm(fd, pb.buf, pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
#include "afh.h"
#include "afs.h"
#include "ipc.h"
#include "afh.h"
#include "afs.h"
#include "ipc.h"
/** \file playlist.c Functions for loading and saving playlists. */
/** \file playlist.c Functions for loading and saving playlists. */
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
.max_size = shm_get_shmmax(),
.private_data = &(struct afs_max_size_handler_data) {
.fd = fd,
},
.max_size_handler = afs_max_size_handler,
};
},
.max_size_handler = afs_max_size_handler,
};
osl_rbtree_loop(playlists_table, BLOBCOL_ID, &pb,
check_playlist);
if (pb.offset)
osl_rbtree_loop(playlists_table, BLOBCOL_ID, &pb,
check_playlist);
if (pb.offset)
- pass_buffer_as_shm(fd, pb.buf, pb.offset);
+ pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);