How to use a variant dictionary (`a{sv}`) in dbus-send - dbus

I have some trouble with dbus-send when using a{sv}
Calling a method with in_signature='a{ss}' seems to work using the
following command line:
dbus-send --dest="org.test.TestService"
/org/test/TestService/object org.test.TestService.method1 dict:string:string:"a","1","b","2"
Now I would like to have a dictionary with a variant type for values
(in_signature=a{sv}),
How can I use it in dbus-send?

Not possible with dbus-send
As mentioned, dbus-send does not support all Dbus types. From dbus-send man page:
Also, dbus-send does not permit empty containers or nested containers (e.g. arrays of variants).
But possible gdbus
Buried in https://www.freedesktop.org/software/gstreamer-sdk/data/docs/2012.5/gio/gdbus.html we see this:
gdbus call --session \
--dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications \
--method org.freedesktop.Notifications.Notify \
my_app_name \
42 \
gtk-dialog-info \
"The Summary" \
"Here's the body of the notification" \
[] \
{} \
5000
Bonus: this method returns the id, so you can close or replace the notification.

Although D-Bus supports signatures such as a{sv}, dbus-send does not. This is from the dbus-send man page:
"...D-Bus supports more types than these, but dbus-send currently does not. Also, dbus-send does not permit empty containers or nested containers (e.g. arrays of variants)."
So as far as I can understand it, you cannot send a dict of string:variant using dbus-send.

You need to compile dbus-send with the following patch.
https://chromium-review.googlesource.com/#/c/12323/2/sys-apps/dbus/files/dbus-1.4.12-send-variant-dict.patch
FYR, I uploaded the patched full source at this link.
https://gitlab.com/mujicion/dbus-send.git

I compiled the new version of dbus-send but still has an issue for sending a{sv}.Can you pl provide the syntax for this

Related

How can I generate a Syntastic config file using premake?

Syntastic is a source code linter plugin for the Vim editor.
It does various syntax and heuristic checks, using external tools. In the case of C and C++ code, this frequently involves running a compiler on the code.
In order to invoke the compiler, Syntastic reads a config file that contains command-line arguments that should be used to invoke the compiler.
Obviously, the "real" compilation in the project is handled by premake but this means there are potentially two sources of truth -- the compiler flags written into the Syntastic config file, and the compiler flags written by premake into the build scripts.
I'd like to resolve this by having premake generate the compiler flags in the Syntastic config file, also.
This seems like a fairly straightforward task with various possible approaches -- generate a fake compiler, invent a pre-build task, etc. But I don't know enough about the innards of premake to know which of these approaches is the right one.
How can I get premake to generate my syntastic.config file?
I looked into a few different kinds of projects under premake5 -- there have been several added to the documentation recently. None of them quite got me there.
The problem is that what I want to do is either "always create the file" or "create the file when the premake5.lua file changes." That makes things difficult, but not totally impossible.
However, the generated file is not an input file for any of the projects, so that apparently pushes it over the edge from difficult to "not possible ATM".
I tried doing what premake calls Custom Build Commands, but this needs the generated file to be a piece of source code it can use to build with. If this isn't the case, apparently the dependency graph breaks and the makefile is generated without a dependency on the file. :(
In order to just get this working, I opted to just regenerate the file all the time using a prebuild command:
prebuildcommands {
"$(SILENT) "
..repo_dir.."etc/write-syntastic-config.sh $(ALL_CFLAGS)"
.." > "
..repo_dir.."etc/syntastic.config"
}
The key value in this is $(ALL_CFLAGS), the variable used by the Makefile generator to hold the stuff I want.
Syntastic's config file and its use of the config file is a bit touchy. It doesn't accept -L and -l options, or perhaps gcc doesn't accept them in whatever mode it is invoked with. Regardless, some filtering is required the args can be used.
Also, syntastic processes the lines looking specifically for -I, which it then handles in a special way: the include paths are treated as either absolute, or relative to the config file.
Finally, syntastic doesn't appear to know about -isystem, another include-directory option for gcc. So that has to be handles differently.
If anyone cares, here's the script I'm using:
etc/write-syntastic-config.sh
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
PENDING=""
PENDING_DIR=false
printf '# Generated by %s\n' "$(basename "$0")"
CFG_FILE_DIR="$(dirname "$0")"
for ARG in "$#"
do
#printf >&2 "arg=>%s<\\n" "$ARG"
case "$ARG" in
-I| \
-L)
PENDING="$ARG"
PENDING_DIR=true
;;
-isystem)
# -isystem is like -I, except syntastic doesn't know it
printf '%s\n' "$ARG"
PENDING_DIR=true
;;
-I*| \
-L*) PENDING_DIR=true
PENDING="${ARG:0:2}"
ARG="${ARG/#-?/}"
;;& #<-- Resume matching cases (i.e, "goto next case")
*) if $PENDING_DIR
then
ARG="$(realpath -m \
--relative-to "$CFG_FILE_DIR" \
"$ARG")"
fi
case "$PENDING" in
-L) : ignore it ;;
"") printf '%s\n' "$ARG" ;;
*) printf '%s %s\n' "$PENDING" "$ARG" ;;
esac
PENDING=""
PENDING_DIR=false
;;
esac
done
exit 0

Gnome 3: Call sushi, the Nautilus quick file previewer via DBus

In Gnome 3, Nautilus has a new file previewer called Sushi. You can select a file in Nautilus, hit the spacebar and it will show a quick preview. This is very similar to what Quick Look (Preview) on OSX does. Quick Look has a command line interface that allows you to use Quick Look from inside your own application. Sushi does not appear to allow this.
It appears the only way to call sushi it via dbus. (If you know how to call it via the cmd line, even better) I found sushi's source for where it registers its dbus messages but cannot figure out how to call it.
Here's what I tried:
> qdbus org.gnome.NautilusPreviewer /org/gnome/NautilusPreviewer org.gnome.NautilusPreviewer.ShowFile /foo/bar/baz.png 0x1c00010 0
Error: org.gnome.gjs.JSError.Error
Argument 'parent' (type interface) may not be null
I'm a novice when it comes to dbus, so maybe I'm missing something obvious
> dbus-send --print-reply --dest=org.gnome.NautilusPreviewer /org/gnome/NautilusPreviewer org.gnome.NautilusPreviewer.ShowFile string:"/foo/bar/baz.png" uint32:0x1c00010 uint32:1
Error org.freedesktop.DBus.Error.InvalidArgs: Type of message, '(suu)', does not match expected type '(sib)'
Try this:
dbus-send --print-reply --dest=org.gnome.NautilusPreviewer /org/gnome/NautilusPreviewer org.gnome.NautilusPreviewer.ShowFile string:"file:///foo/bar/baz.png" int32:0 boolean:false
Your second error means you used incorrect types: you should use string, int32 and boolean (sib), not string and two unsigned integers (suu).
Also please note that you should use URI, not raw filename - just add file:// scheme prefix.
Second parameter should be xid of Window you want to show your preview over. But 0 works for me.
I am not an expert on the question and pretty novice to linux. I faced this problem too and manage to solve it by reinstalling the dbg package.
I noticed that during the upgrade to 19.10 this package add necessarily to be remove to pursue with the installation.
Once the upgrade was performed, gnome-showed the same error as mentioned #Matthew Levine in the first post. reinstall gdb solved the issue for me.

OpenSSL linking: missing extern Symbol BIGNUM_it

I want to use some features of OpenSSL(1.0.1j) on multiple devices. One requirement is to minimize the size of the code. The OpenSSL code is linked statically to mine. I am only using the RSA_public_decrypt, BIO and PEM->RSA decoding methods. To achieve this, i'm currently compiling OpenSSL not the standard autotools way. I have already stripped out some code that i never use. The only symbol i can not resolve is _BIGNUM_it.
It is declared in asn1t.h with:
DECLARE_ASN1_ITEM(BIGNUM)
and
#define DECLARE_ASN1_ITEM(name) \
extern const ASN1_ITEM name##_it;
It is used in rsa_asn1.c:
ASN1_SIMPLE(RSA, n, BIGNUM),
ASN1_SIMPLE(RSA, e, BIGNUM),
which resolves to:
#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)
and
#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
(flags), (tag), offsetof(stname, field),\
#field, ASN1_ITEM_ref(type) }
and
#define ASN1_ITEM_ref(iptr) (&(iptr##_it))
I searched for other symbols used that way. They were implemented using IMPLEMENT_ASN1_TYPE(). I searched all OpenSSL Code for something like that using BIGNUM and didn't find anything. Also I tried to use IMPLEMENT_ASN1_TYPE(BIGNUM) in the code, which resulted in thousands of errors.
Is this something provided from the outside? Do i miss a .c file? If yes, which?
Thanks for your help!
I found the symbol in asn1/x_bignum.c.

Linux analogue to Windows' SetSystemPowerState?

I'm writing a program in C with a mind on cross-compatibility, but I don't think I'm going to be able to get away without at least some platform specific #ifdefs.
One of the required features is to be able to put the system into Suspend power mode. On Windows, with the appropriate OS config, this is accomplished by using the SetSystemPowerState() function (after an appropriate security dance prior to the call).
Is there a Linux function that will do the same thing? I suspect it's there but so far my searching is only picking up command line programs and not any headers or function signatures.
Try to install pm-utils. look here
Depend on your Linux, you better use yum, apt-get, etc...
Then it would be something like: system("pm-hibernate") or system("pm-suspend")
Maybe you'll need to use a full path to the utility.
It is open source, so if you want to program it with c, open the sources and check how it done.
EDIT:
A c solution is to use d-bus look here
it is a c source code, check how the dbus-send.c (in the tools dir) is working (with the arguments below).
Build all, and all you need is to link with the libdbus.
cpmmand line to dbus-send tool:
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Suspend \
int32:0
Make a file susp.sh and save
dbus-send --system --print-reply --dest=org.freedesktop.Hal \/org/freedesktop/Hal/devices/computer \org.freedesktop.Hal.Device.SystemPowerManagement.Suspend \int32:0
Make a file resume.sh and save
dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer \org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate
Now add:
system("sh susp.sh");
To suspend and
system("sh resume.sh");
To resume

how to achieve linux's inotify-tools shell methods on osx

To monitor a file in linux, I can use inotify-tools like this
#!/bin/bash
# with inotify-tools installed, watch for modification of file passed as first param
while inotifywait -e modify $1; do
# do something here
done
but how would I achieve this in OSX?
If you want to wrap this into a Python script, you can use Watchdog, which works with both Linux and OSX.
https://pypi.python.org/pypi/watchdog
Here is what it looks like to replace pyinotify with watchdog:
https://github.com/raphdg/baboon/commit/2c115da63dac16d0fbdc9b45067d0ab0960143ed
Watchdog also has a shell utility called watchmedo:
watchmedo shell-command \
--patterns="*.py;*.txt" \
--recursive \
--command='echo "${watch_src_path}"' \
.
Yes, you can use the FSEvents API
You can use entr tool. Example usage:
ls some_file | entr do_something
On Mac install via Brew: brew install entr.

Resources