static void cmd_debug_show_cursors(struct watchman_client *client, json_t *args) { w_root_t *root; json_t *resp, *cursors; w_ht_iter_t i; /* resolve the root */ if (json_array_size(args) != 2) { send_error_response(client, "wrong number of arguments for 'debug-show-cursors'"); return; } root = resolve_root_or_err(client, args, 1, false); if (!root) { return; } resp = make_response(); w_root_lock(root); cursors = json_object_of_size(w_ht_size(root->cursors)); if (w_ht_first(root->cursors, &i)) do { w_string_t *name = w_ht_val_ptr(i.key); set_prop(cursors, name->buf, json_integer(i.value)); } while (w_ht_next(root->cursors, &i)); w_root_unlock(root); set_prop(resp, "cursors", cursors); send_and_dispose_response(client, resp); w_root_delref(root); }
/* watch /root */ static void cmd_watch(struct watchman_client *client, json_t *args) { w_root_t *root; json_t *resp; /* resolve the root */ if (json_array_size(args) != 2) { send_error_response(client, "wrong number of arguments to 'watch'"); return; } root = resolve_root_or_err(client, args, 1, true); if (!root) { return; } resp = make_response(); w_root_lock(root); if (root->failure_reason) { set_prop(resp, "error", json_string_nocheck(root->failure_reason->buf)); } else if (root->cancelled) { set_prop(resp, "error", json_string_nocheck("root was cancelled")); } else { set_prop(resp, "watch", json_string_nocheck(root->root_path->buf)); } send_and_dispose_response(client, resp); w_root_unlock(root); w_root_delref(root); }
std::unique_ptr<cbmc_solverst::solvert> cbmc_solverst::get_default() { auto solver=util_make_unique<solvert>(); if(options.get_bool_option("beautify") || !options.get_bool_option("sat-preprocessor")) // no simplifier { // simplifier won't work with beautification solver->set_prop(util_make_unique<satcheck_no_simplifiert>()); } else // with simplifier { solver->set_prop(util_make_unique<satcheckt>()); } solver->prop().set_message_handler(get_message_handler()); auto bv_cbmc=util_make_unique<bv_cbmct>(ns, solver->prop()); if(options.get_option("arrays-uf")=="never") bv_cbmc->unbounded_array=bv_cbmct::unbounded_arrayt::U_NONE; else if(options.get_option("arrays-uf")=="always") bv_cbmc->unbounded_array=bv_cbmct::unbounded_arrayt::U_ALL; solver->set_prop_conv(std::move(bv_cbmc)); return solver; }
/* find /root [patterns] */ static void cmd_find(struct watchman_client *client, json_t *args) { w_root_t *root; w_query *query; char *errmsg = NULL; struct w_query_field_list field_list; w_query_res res; json_t *response; json_t *file_list; char clockbuf[128]; /* resolve the root */ if (json_array_size(args) < 2) { send_error_response(client, "not enough arguments for 'find'"); return; } root = resolve_root_or_err(client, args, 1, false); if (!root) { return; } query = w_query_parse_legacy(root, args, &errmsg, 2, NULL, NULL, NULL); if (errmsg) { send_error_response(client, "%s", errmsg); free(errmsg); w_root_delref(root); return; } w_query_legacy_field_list(&field_list); if (client->client_mode) { query->sync_timeout = 0; } if (!w_query_execute(query, root, &res, NULL, NULL)) { send_error_response(client, "query failed: %s", res.errmsg); w_query_result_free(&res); w_root_delref(root); w_query_delref(query); return; } w_query_delref(query); file_list = w_query_results_to_json(&field_list, res.num_results, res.results); w_query_result_free(&res); response = make_response(); if (clock_id_string(res.root_number, res.ticks, clockbuf, sizeof(clockbuf))) { set_prop(response, "clock", json_string_nocheck(clockbuf)); } set_prop(response, "files", file_list); send_and_dispose_response(client, response); w_root_delref(root); }
static json_t *build_subscription_results( struct watchman_client_subscription *sub, w_root_t *root) { w_query_res res; json_t *response; json_t *file_list; char clockbuf[128]; w_log(W_LOG_DBG, "running subscription rules! since %" PRIu32 "\n", sub->since.ticks); // Subscriptions never need to sync explicitly; we are only dispatched // at settle points which are by definition sync'd to the present time sub->query->sync_timeout = 0; if (!w_query_execute(sub->query, root, &res, subscription_generator, sub)) { w_log(W_LOG_ERR, "error running subscription query: %s", res.errmsg); w_query_result_free(&res); return NULL; } w_log(W_LOG_DBG, "subscription generated %" PRIu32 " results\n", res.num_results); file_list = w_query_results_to_json(&sub->field_list, res.num_results, res.results); w_query_result_free(&res); if (res.num_results == 0) { return NULL; } response = make_response(); if (clock_id_string(sub->since.ticks, clockbuf, sizeof(clockbuf))) { set_prop(response, "since", json_string_nocheck(clockbuf)); } if (clock_id_string(res.ticks, clockbuf, sizeof(clockbuf))) { set_prop(response, "clock", json_string_nocheck(clockbuf)); } sub->since.is_timestamp = false; sub->since.ticks = res.ticks; set_prop(response, "files", file_list); set_prop(response, "root", json_string(root->root_path->buf)); set_prop(response, "subscription", json_string(sub->name->buf)); return response; }
/* debug-ageout */ static void cmd_debug_ageout(struct watchman_client *client, json_t *args) { w_root_t *root; json_t *resp; int min_age; /* resolve the root */ if (json_array_size(args) != 3) { send_error_response(client, "wrong number of arguments for 'debug-ageout'"); return; } root = resolve_root_or_err(client, args, 1, false); if (!root) { return; } min_age = json_integer_value(json_array_get(args, 2)); resp = make_response(); w_root_lock(root); w_root_perform_age_out(root, min_age); w_root_unlock(root); set_prop(resp, "ageout", json_true()); send_and_dispose_response(client, resp); w_root_delref(root); }
static void cmd_debug_recrawl(struct watchman_client *client, json_t *args) { w_root_t *root; json_t *resp; /* resolve the root */ if (json_array_size(args) != 2) { send_error_response(client, "wrong number of arguments for 'debug-recrawl'"); return; } root = resolve_root_or_err(client, args, 1, false); if (!root) { return; } resp = make_response(); w_root_lock(root); w_root_schedule_recrawl(root, "debug-recrawl"); w_root_unlock(root); set_prop(resp, "recrawl", json_true()); send_and_dispose_response(client, resp); w_root_delref(root); }
void send_error_response(struct watchman_client *client, const char *fmt, ...) { char buf[WATCHMAN_NAME_MAX]; va_list ap; json_t *resp = make_response(); json_t *errstr; va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); errstr = typed_string_to_json(buf, W_STRING_MIXED); set_prop(resp, "error", errstr); json_incref(errstr); w_perf_add_meta(&client->perf_sample, "error", errstr); if (client->current_command) { char *command = NULL; command = json_dumps(client->current_command, 0); w_log(W_LOG_ERR, "send_error_response: %s failed: %s\n", command, buf); free(command); } else { w_log(W_LOG_ERR, "send_error_response: %s\n", buf); } send_and_dispose_response(client, resp); }
void w_log_to_clients(int level, const char *buf) { json_t *json = NULL; w_ht_iter_t iter; if (!clients) { return; } pthread_mutex_lock(&w_client_lock); if (w_ht_first(clients, &iter)) do { struct watchman_client *client = w_ht_val_ptr(iter.value); if (client->log_level != W_LOG_OFF && client->log_level >= level) { json = make_response(); if (json) { set_prop(json, "log", json_string_nocheck(buf)); if (!enqueue_response(client, json, true)) { json_decref(json); } } } } while (w_ht_next(clients, &iter)); pthread_mutex_unlock(&w_client_lock); }
int read_prop(MNL_CONFIG_T* prConfig, const char* name) { FILE *fp = fopen(name, "rb"); char *key, *val; if (!fp){ MNL_MSG("%s: open %s fail!\n",__FUNCTION__,name); return -1; } while(fgets(propbuf, sizeof(propbuf), fp)) { if (get_prop(propbuf, &key, &val)) { MNL_MSG("%s: Get Property fails!!\n", __FUNCTION__); fclose(fp); return -1; } if (!key || !val) continue; //MNL_MSG("%s: Get Property: '%s' => '%s'\n", __FUNCTION__, key, val); if (set_prop(prConfig, key,val)) { MNL_ERR("%s: Set Property fails!!\n", __FUNCTION__); fclose(fp); return -1; } } fclose(fp); return 0; }
/* Add the current clock value to the response. * must be called with the root locked */ void annotate_with_clock(w_root_t *root, json_t *resp) { char buf[128]; if (current_clock_id_string(root, buf, sizeof(buf))) { set_prop(resp, "clock", json_string_nocheck(buf)); } }
static void print_props(topo_hdl_t *thp, tnode_t *node) { int i, err; nvlist_t *nvl; struct prop_args *pp; if (pcnt == 0) return; for (i = 0; i < pcnt; ++i) { pp = pargs[i]; if (pp->group == NULL) continue; /* * If we have a valid value, this is a request to * set a property. Otherwise, just print the property * group and any specified properties. */ if (pp->value == NULL) { if (pp->prop == NULL) { /* * Print all properties in this group */ if ((nvl = topo_prop_getprops(node, &err)) == NULL) { (void) fprintf(stderr, "%s: failed to " "get %s: %s\n", g_pname, pp->group, topo_strerror(err)); continue; } else { print_all_props(thp, node, nvl, pp->group); nvlist_free(nvl); continue; } } if (topo_prop_getprop(node, pp->group, pp->prop, NULL, &nvl, &err) < 0) { (void) fprintf(stderr, "%s: failed to get " "%s.%s: %s\n", g_pname, pp->group, pp->prop, topo_strerror(err)); continue; } else { print_pgroup(thp, node, pp->group, NULL, NULL, 0); print_prop_nameval(thp, node, nvl); nvlist_free(nvl); } } else { set_prop(thp, node, NULL, pp); } } }
json_t *make_response(void) { json_t *resp = json_object(); set_prop(resp, "version", json_string_nocheck(PACKAGE_VERSION)); return resp; }
static gboolean set_prop_list(GVariantIter* iter) { gchar* val; gchar* key; while (g_variant_iter_loop(iter, "{ss}", &key, &val)) { set_prop(key, val); } return TRUE; }
/* get-pid */ void cmd_get_pid(struct watchman_client *client, json_t *args) { json_t *resp = make_response(); unused_parameter(args); set_prop(resp, "pid", json_integer(getpid())); send_and_dispose_response(client, resp); }
/* get-sockname */ void cmd_get_sockname(struct watchman_client *client, json_t *args) { json_t *resp = make_response(); unused_parameter(args); set_prop(resp, "sockname", json_string(get_sock_name())); send_and_dispose_response(client, resp); }
/* trigger-del /root triggername * Delete a trigger from a root */ static void cmd_trigger_delete(struct watchman_client *client, json_t *args) { w_root_t *root; json_t *resp; json_t *jname; w_string_t *tname; bool res; root = resolve_root_or_err(client, args, 1, false); if (!root) { return; } if (json_array_size(args) != 3) { send_error_response(client, "wrong number of arguments"); w_root_delref(root); return; } jname = json_array_get(args, 2); if (!json_is_string(jname)) { send_error_response(client, "expected 2nd parameter to be trigger name"); w_root_delref(root); return; } tname = json_to_w_string_incref(jname); w_root_lock(root, "trigger-del"); res = w_ht_del(root->commands, w_ht_ptr_val(tname)); w_root_unlock(root); if (res) { w_state_save(); } w_string_delref(tname); resp = make_response(); set_prop(resp, "deleted", json_boolean(res)); json_incref(jname); set_prop(resp, "trigger", jname); send_and_dispose_response(client, resp); w_root_delref(root); }
static void cmd_shutdown(struct watchman_client *client, json_t *args) { json_t *resp = make_response(); unused_parameter(args); w_log(W_LOG_ERR, "shutdown-server was requested, exiting!\n"); w_request_shutdown(); set_prop(resp, "shutdown-server", json_true()); send_and_dispose_response(client, resp); }
gmx_bool gmx_atomprop_query(gmx_atomprop_t aps, int eprop, const char *resnm, const char *atomnm, real *value) { gmx_atomprop *ap = (gmx_atomprop*) aps; int j; #define MAXQ 32 char atomname[MAXQ], resname[MAXQ]; gmx_bool bExact; set_prop(aps, eprop); if ((strlen(atomnm) > MAXQ-1) || (strlen(resnm) > MAXQ-1)) { if (debug) { fprintf(debug, "WARNING: will only compare first %d characters\n", MAXQ-1); } } if (isdigit(atomnm[0])) { int i; /* put digit after atomname */ for (i = 1; i < MAXQ-1 && atomnm[i] != '\0'; i++) { atomname[i-1] = atomnm[i]; } atomname[i-1] = atomnm[0]; atomname[i] = '\0'; } else { strncpy(atomname, atomnm, MAXQ-1); } strncpy(resname, resnm, MAXQ-1); j = get_prop_index(&(ap->prop[eprop]), ap->restype, resname, atomname, &bExact); if (eprop == epropVDW && !ap->bWarnVDW) { vdw_warning(stdout); ap->bWarnVDW = TRUE; } if (j >= 0) { *value = ap->prop[eprop].value[j]; return TRUE; } else { *value = ap->prop[eprop].def; return FALSE; } }
/* trigger /root triggername [watch patterns] -- cmd to run * Sets up a trigger so that we can execute a command when a change * is detected */ void cmd_trigger(struct watchman_client *client, json_t *args) { w_root_t *root; struct watchman_trigger_command *cmd; json_t *resp; json_t *trig; char *errmsg = NULL; root = resolve_root_or_err(client, args, 1, true); if (!root) { return; } if (json_array_size(args) < 3) { send_error_response(client, "not enough arguments"); goto done; } trig = json_array_get(args, 2); if (json_is_string(trig)) { trig = build_legacy_trigger(client, args); if (!trig) { goto done; } } else { // Add a ref so that we don't need to conditionally decref later // for the legacy case later json_incref(trig); } cmd = w_build_trigger_from_def(root, trig, &errmsg); json_decref(trig); if (!cmd) { send_error_response(client, "%s", errmsg); goto done; } w_root_lock(root); w_ht_replace(root->commands, w_ht_ptr_val(cmd->triggername), w_ht_ptr_val(cmd)); w_root_unlock(root); w_state_save(); resp = make_response(); set_prop(resp, "triggerid", json_string_nocheck(cmd->triggername->buf)); send_and_dispose_response(client, resp); done: if (errmsg) { free(errmsg); } w_root_delref(root); }
JSBool add_prop(JSContext* jscx, JSObject* jsobj, jsval key, jsval* rval) { JSObject* obj = NULL; if(JSVAL_IS_NULL(*rval) || !JSVAL_IS_OBJECT(*rval)) return JS_TRUE; obj = JSVAL_TO_OBJECT(*rval); if(JS_ObjectIsFunction(jscx, obj)) return set_prop(jscx, jsobj, key, rval); return JS_TRUE; }
/* watch-list * Returns a list of watched roots */ static void cmd_watch_list(struct watchman_client *client, json_t *args) { json_t *resp; json_t *root_paths; unused_parameter(args); resp = make_response(); root_paths = w_root_watch_list_to_json(); set_prop(resp, "roots", root_paths); send_and_dispose_response(client, resp); }
/* version */ void cmd_version(struct watchman_client *client, json_t *args) { json_t *resp = make_response(); unused_parameter(args); #ifdef WATCHMAN_BUILD_INFO set_prop(resp, "buildinfo", json_string(WATCHMAN_BUILD_INFO)); #endif send_and_dispose_response(client, resp); }
/* trigger-del /root triggername * Delete a trigger from a root */ void cmd_trigger_delete(struct watchman_client *client, json_t *args) { w_root_t *root; json_t *resp; const char *name; w_string_t *tname; bool res; root = resolve_root_or_err(client, args, 1, false); if (!root) { return; } if (json_array_size(args) != 3) { send_error_response(client, "wrong number of arguments"); w_root_delref(root); return; } name = json_string_value(json_array_get(args, 2)); if (!name) { send_error_response(client, "expected 2nd parameter to be trigger name"); w_root_delref(root); return; } tname = w_string_new(name); w_root_lock(root); res = w_ht_del(root->commands, (w_ht_val_t)tname); w_root_unlock(root); w_state_save(); w_string_delref(tname); resp = make_response(); set_prop(resp, "deleted", json_boolean(res)); set_prop(resp, "trigger", json_string_nocheck(name)); send_and_dispose_response(client, resp); w_root_delref(root); }
/* watch-del /root * Stops watching the specified root */ static void cmd_watch_delete(struct watchman_client *client, json_t *args) { w_root_t *root; json_t *resp; /* resolve the root */ if (json_array_size(args) != 2) { send_error_response(client, "wrong number of arguments to 'watch-del'"); return; } root = resolve_root_or_err(client, args, 1, false); if (!root) { return; } resp = make_response(); set_prop(resp, "watch-del", json_boolean(w_root_stop_watch(root))); set_prop(resp, "root", json_string_nocheck(root->root_path->buf)); send_and_dispose_response(client, resp); w_root_delref(root); }
int gmx_atomprop_atomnumber(gmx_atomprop_t aps,const char *elem) { gmx_atomprop *ap = (gmx_atomprop*) aps; int i; set_prop(aps,epropElement); for(i=0; (i<ap->prop[epropElement].nprop); i++) { if (gmx_strcasecmp(ap->prop[epropElement].atomnm[i],elem) == 0) { return gmx_nint(ap->prop[epropElement].value[i]); } } return NOTSET; }
char *gmx_atomprop_element(gmx_atomprop_t aps,int atomnumber) { gmx_atomprop *ap = (gmx_atomprop*) aps; int i; set_prop(aps,epropElement); for(i=0; (i<ap->prop[epropElement].nprop); i++) { if (gmx_nint(ap->prop[epropElement].value[i]) == atomnumber) { return ap->prop[epropElement].atomnm[i]; } } return NULL; }
void w_cancel_subscriptions_for_root(w_root_t *root) { w_ht_iter_t iter; pthread_mutex_lock(&w_client_lock); if (w_ht_first(clients, &iter)) { do { struct watchman_user_client *client = w_ht_val_ptr(iter.value); w_ht_iter_t citer; if (w_ht_first(client->subscriptions, &citer)) { do { struct watchman_client_subscription *sub = w_ht_val_ptr(citer.value); if (sub->root == root) { json_t *response = make_response(); w_log(W_LOG_ERR, "Cancel subscription %.*s for client:stm=%p due to " "root cancellation\n", sub->name->len, sub->name->buf, client->client.stm); set_prop(response, "root", w_string_to_json(root->root_path)); set_prop(response, "subscription", w_string_to_json(sub->name)); set_prop(response, "unilateral", json_true()); set_prop(response, "canceled", json_true()); if (!enqueue_response(&client->client, response, true)) { w_log(W_LOG_DBG, "failed to queue sub cancellation\n"); json_decref(response); } w_ht_iter_del(client->subscriptions, &citer); } } while (w_ht_next(client->subscriptions, &citer)); } } while (w_ht_next(clients, &iter)); } pthread_mutex_unlock(&w_client_lock); }
/* unsubscribe /root subname * Cancels a subscription */ void cmd_unsubscribe(struct watchman_client *client, json_t *args) { w_root_t *root; const char *name; w_string_t *sname; bool deleted; json_t *resp; root = resolve_root_or_err(client, args, 1, false); if (!root) { return; } name = json_string_value(json_array_get(args, 2)); if (!name) { send_error_response(client, "expected 2nd parameter to be subscription name"); w_root_delref(root); return; } sname = w_string_new(name); pthread_mutex_lock(&w_client_lock); deleted = w_ht_del(client->subscriptions, w_ht_ptr_val(sname)); pthread_mutex_unlock(&w_client_lock); w_string_delref(sname); resp = make_response(); set_prop(resp, "unsubscribe", json_string_nocheck(name)); set_prop(resp, "deleted", json_boolean(deleted)); send_and_dispose_response(client, resp); w_root_delref(root); }
void send_error_response(struct watchman_client *client, const char *fmt, ...) { char buf[WATCHMAN_NAME_MAX]; va_list ap; json_t *resp = make_response(); va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); set_prop(resp, "error", json_string_nocheck(buf)); send_and_dispose_response(client, resp); }