59 Commits
Author SHA1 Message Date
Otavio Pontes 2b61f8a237 hash: Force a minimum size for swupd hash
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-08-02 16:29:32 -07:00
Otavio Pontes a547d9974d sys: Add NULL on run_command() call
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-31 12:16:13 -07:00
Otavio Pontes d9710e78d0 sys: Check for errors on calls to dup2 and open
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-26 15:52:57 -07:00
Castulo Martinez 57fc7ce3ab Fix logger format when printing debug messages
Debug messages need to be treated a little differently from other
messages, since they include more information, like the time, file and
line of code. So certain things like having carriage returns and
messages with only a line break should not be allowed since they would
mess up the debug output.

This commit fixes that issue

Closes #1009

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-07-25 10:17:24 -07:00
Otavio Pontes 4cb70835ba global: Don't depend on a static variable to store context values
Add a data parameter to config parser to make the config_parse function easier to
be reused for other cases. And adapting config_loader to use that new function.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-19 14:18:05 -07:00
Otavio Pontes 1765f33b59 config_parser: Don't allocate extra memory for key and value
Key and value are already valid strings so we can use them without
duplicating them in memory.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-18 15:48:24 -07:00
Castulo Martinez 069ec11ca8 Fix format of do_staging when reporting progress
The function do_staging is regularly used within a loop to stage all the
files for a given bundle-add or update, repair, etc. However when the
loop contains a progress report (with a percentage), if there are errors
in the do_staging function, they get printed in the same line as the
percentage, messing up the output. Like this:

...22%Warning: Update target directory does not exist: some_file...

This commit fixes that output by adding a carriage return at the
beginning of each message do_staging could print so it would overlap
with the percentage value effectively deleting it.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-07-17 14:24:01 -07:00
Castulo Martinez ca48ffbb6b Add support for starting with "\n" or "\r" in logger
The logger functions (warn, error, debug) do not support adding line
breaks or carriage returns at the beginning of the message, because
the line break would be inserted between the label and the message,
or the carriage return would cause the message to overlap the label.

For example, for a code line like this:

warn("\nmy message\n")

The output would look like this:

Warning:
my message

This commit adds support to the logger functions to use "\n" and "\r"
at the beginning of the message so it provides more control over the
output.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>

Adding carriage return to outpu

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-07-17 14:24:01 -07:00
Otavio Pontes 0c3cc3fb66 string: Add string substitution function
And used it in config_loader

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-17 14:16:56 -07:00
Otavio Pontes b245ec2c6d strings: Add note about case insensitivity of function
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-17 14:16:56 -07:00
Otavio Pontes b96eb3f17e config_parser: Skip to next item if a section is found
Not a bug, but if a section is found we don't need to continue parsing the line

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-17 14:16:56 -07:00
Otavio Pontes 4ca53af48a progress: Add a flag to run swupd without progress report
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-07-15 11:44:24 -07:00
Castulo Martinez c2a4763ff3 Adding configuration file parser for swupd
swupd has many flags that can be used for fine tunning its
functionality. In some cases users may want to include a flag with every
swupd command they run.

This commit gives the ability to provide swupd flags via options in a
configuration file that swupd will read before running the command.

The configuration file is an INI style file tha  can include sections
so users can specify options that should only apply to a specific
command. The biggest advantage of this is to be able to fine tune the
flags that should apply for each command.

For example a user could set a global flag that would apply to every
swupd command, and then turn that flag off for a specific command by
unsetting it in the command's section.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-06-28 13:06:11 -07:00
Arzhan Kinzhalin c07b47abc1 Prevent swupd from running interactive commands.
Replace stdin with /dev/null for children. This addresses the issue with
hangs when running update hooks which for whatever reason may expect
interactive input.
2019-06-25 15:56:50 -07:00
Arzhan Kinzhalin d9373b1709 Clean up. 2019-06-25 15:56:50 -07:00
Castulo Martinez ec9eeee4d0 Return correct code when bad path in picky-tree
When using "diagnose --picky --picky-tree /fake/path" swupd was exiting
with error code 34 (SWUPD_OUT_OF_MEMORY_ERROR) which was incorrect.

This commit fixes the issue by returning the correct code 29
(SWUPD_COULDNT_LIST_DIR) in those situations.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-06-25 15:51:29 -07:00
Castulo Martinez 0cc96ed702 Adding a progress overflow protection
When reporting download progress, we should never have a percentage
bigger than 100%, but if for some reason we do (due to a bug), we don't
want that percentage slipping all the way to the end user.

This commit limits the percentage we display to 100 maximum.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-06-14 14:56:34 -07:00
Castulo Martinez 7d295f3ec5 Fix the output when diagnosing a system
Currently when running diagnose, and a problem is found (a missing
file, a corrupt file, or an extraneous file), swupd shows the output
like this:

Verifying files
	...12%
Hash mismatch for file: /usr/bin/somefile
	...100%
Inspected 632545 files

So it splits the percentage that shows the progress of the action in two
lines. This commit fixes the output so it looks like this instead:

Checking for missing files
	...100%

Checking for corrupt files
 -> Hash mismatch for file: /usr/bin/mixer
 -> Hash mismatch for file: /usr/bin/mixin
 -> Hash mismatch for file: /usr/bin/swupd-extract
 -> Hash mismatch for file: /usr/bin/swupd-inspector
 -> Hash mismatch for file: /usr/share/zsh/site-functions/_mixer
	...100%

Checking for extraneous files
	...100%

Inspected 632545 files

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-06-06 15:37:21 -07:00
Castulo Martinez eb579bcdae Adding a line break when reaching 100% in progress
This commit adds a line break at the end of the progress report (when we
reach 100%) so we don't have to manually include it every time we report
progress.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-06-06 15:37:21 -07:00
Otavio Pontes 1272040876 bundle-list: local bundle list should work without root
When we changed the init swupd function we stopped supporting bundle-list as root.
Adding this back on.
2019-05-31 19:35:33 +00:00
Otavio Pontes 852c70d8d2 sys: Adding helper to dirname and path_join
Dirname() is a very tricky function to use. Create a wrapper to make it a
lot easier. The only downside is an extra strdup, but it's worth it.

sys_path_join() is a function to make it easier to concatenate 2 paths using
correct separator and avoid duplicated '/'

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-05-14 14:28:27 -07:00
Castulo Martinez a2593a556e Print the json output to stdout instead of stderr
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-05-13 14:29:27 -07:00
Otavio Pontes c0703398a0 sys: Adding a missing --no-block flag on call that shouldn't block
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-24 09:32:59 -07:00
Otavio Pontes d4ddcb2c9a docs: Use doxygen style on header API documentation
Documentation coverage on src/lib is now 100% and the goal is to eventually
reach that for everything on src/.

Also improve some documention on headers.
2019-04-23 13:27:10 -07:00
Castulo Martinez 591aef2ebe Report progress based on downloaded content
When swupd reports progress of content it needs, it does so by counting
how many files it needs to download (fullfiles or packs) and how many it
has already downloaded. This gives a rough estimate of what is the
progress of the overall download, but it can also be very misleading
since some files may be very different in size compared to others. This
is specially true when talking about packs, one pack could be a couple
of megabytes big while another one could be a few hundred megabytes.

This commit adds a curl callback that can be used to report download
progress periodically based on how many bytes have been downloaded vs
how many bytes have to be downloaded in total, giving the ability to report
progress accurately.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-04-18 10:29:49 -07:00
Otavio Pontes 88101532bc macros: Move UNUSED_PARAM to macros
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-18 10:20:41 -07:00
Otavio Pontes 6f97b70003 archives: Don't assume tarball includes '/' for directories
At first I assumed that all tarballs would have a trailing '/' for directories
and this isn't true. But we can't assume that we won't have a trailing '/'. So
archives_check_single_file_tarball() is now ignoring trailing '/' when comparing
files. That is the same behavior of the function that
archives_check_single_file_tarball() replaced.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-15 13:29:00 -07:00
Otavio Pontes d4f34bc1a9 archive: Use libarchive to check for tar contents
Stop using binary tar to check for tar contents. Use libarchive instead

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-10 16:52:19 -07:00
Otavio Pontes a688c1e77d archive: Don't mix up ints and bools
It's a bad programming practice to mix both

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-10 16:52:19 -07:00
Otavio Pontes cd3831c696 archives: move archive module to lib
archive is independent from swupd specific code, so move it to lib/

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-10 16:52:19 -07:00
Otavio Pontes d9dedbac91 scripts: Use run_command() instead of system() for all scripts
Also reorganize, change some functions name and create a .h for scripts module.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-10 16:13:54 -07:00
Otavio Pontes 4f21c8339c sys: Fix typo
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-10 16:13:54 -07:00
Otavio Pontes 20922d970b autoupdate: Don't use system() to set up autoupdates
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-10 16:13:54 -07:00
Otavio Pontes 7ef0809882 sys: Use run_command() to print messages to the journal
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-10 16:13:54 -07:00
Otavio Pontes 7e4d607dab sys: First parameter in argv isn't the basename of the binary
The default is to use the full path of the binary that is being executed and
not the basename.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-04-09 12:27:03 -07:00
Castulo Martinez 069af9decf Enabling the --json-output flag as a global option
The --json-output flag can be enabled for every swupd command.

This commit converts it to be a global flag, and enables it in every
swupd command.

Closes #869

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-04-01 12:03:23 -07:00
Otavio Pontes 9d6d8aa894 search: Improving search-file results and speed
Reimplement search file to print output in search time instead of saving
everything to be printed later. This makes search a lot faster and reduce
the memory footprint of this function.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-03-28 16:35:01 -07:00
Castulo Martinez c545a02378 Use logger to print all messages in screen
swupd prints some messages to stdout and others to stderr, this makes
the code somewhat confusing and also it creates a mess regarding which
messages go where. Messages are usually printed using fprintf() and
printf().

This commit replaces all calls to printf and fprintf with one of the
functions that are part of the logger. This will bring many advantages
to the code:
 - readability, it is straightforward to identify where a message needs
to go based on the name of the logger functions.
 - consistency, the output will go to either stderr or stdout depending
on the type of message being printed.
 - the format of the messages will also be consistent, so for example,
if the message is an error the message will automatically include the
"Error: " label in the beginning of the message, this way we avoid
having things like "ERROR:", "error - ", etc...

Closes #864
Closes #294
Closes #489
Closes #433

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-25 16:07:40 -07:00
Castulo Martinez ddfb13b842 Moving functions to report progress to own file
Since the reporting of a process progress could be printed in different
formats in the future, not just JSON, this patch moves those functions
to their own file (progress.c) so it is decoupled from the json
formatter.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-25 16:07:40 -07:00
Castulo Martinez a294fcb0d7 Use percentages to report progress when not a tty
When swupd is run and the stdout is not a tty (for example when
redirecting the output to a file) the progress of a step is being
reported as a sequence of dots, which is not very useful to really
identify how far in the process we are.

This commit changes that behavior so percentages are used to report
progress when not using a tty instead of dots.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-25 16:07:40 -07:00
Castulo Martinez 7d1ceb3806 Add functions to report progress
This commit add a few functions to report partial progress on a given
step, either in JSON format or standard so a user or another app can
tell what is the current progress status of a swupd operation at all
times.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-25 16:07:40 -07:00
Castulo Martinez d7b5193d49 Function to report a status in JSON stream
This commit adds a function that can be used to report the status at the
end of an operation into the JSON stream.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-25 16:07:40 -07:00
Otavio Pontes 06e798c760 Make logging json files more generic
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-03-25 16:07:40 -07:00
Castulo Martinez e13b448e37 Function to format a message before printing
There is the need to print info about swupd operations in a parsable
JSON format.

This function provides a wrapper function to format the messages to
comply with the JSON format if the --json-output flag is used.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-03-25 16:07:40 -07:00
Otavio Pontes 0095689db7 thread_pool: Run tasks in same thread if threads are not supported
If we have any errors on pipe2 syscall or in pthread creation run tasks
in main thread. Also set the max downloads in parallel to 1 to avoid timeouts

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-03-07 13:22:47 -08:00
Brandon Hong 890c9caf17 Fix missed dereferencing operator in string hash function
Signed-off-by: Brandon Hong <brandon.hong@intel.com>
2019-02-25 14:02:49 -08:00
Otavio Pontes 085b520050 Add swupd-inspector command into swupd
Use a binary launcher to load swupd-inspector and execute that
when swupd inspector is run.

Closes #826

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-02-22 09:36:39 -08:00
Otavio Pontes 2f612ef711 sys: Add a helper function to check if a file exists
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-02-12 15:11:00 -08:00
Otavio Pontes 3eebc10b73 strings: Move str to int conversion functions to strings module
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
2019-01-31 10:55:17 -08:00
Castulo Martinez 1d1aa36d8b Use bool as return type when applicable over int
When a function returns a boolean state, explicitly return true or
false instead of returning 0 or 1, it is more readable.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
2019-01-24 15:23:15 -08:00