Commit Graph

86 Commits

Author SHA1 Message Date
Alex
097cbc0c53 fix: lint 2023-05-29 09:24:33 +02:00
cptpcrd
5cbbfd5c8a Close pipe if fork() fails when spawning processes
Prevents potential file descriptor leakage, albeit in a bit of an edge
case.
2023-05-21 12:15:49 -04:00
cptpcrd
df65cab17a Open command pipes as close-on-exec
Avoids a race where the pipe could be inherited by another process
spawning at about the same time. If the other process didn't exit
quickly (e.g. if it was a custom script that did its own looping), it
would keep the write end of the pipe open, and so reading from the pipe
to try to get the command's output would block.

This bug manifested as some custom modules randomly not appearing in the
bar, requiring a reload to fix. The custom script had run and exited,
but the pipe had been inherited by another process, and the thread that
updated the module's output was blocked trying to read from it.
2023-05-21 12:10:44 -04:00
Alex
a6084ea7e6
Merge pull request #2068 from TheRealLorenz/master 2023-04-03 09:44:04 +02:00
Alex
60e0584d16 fix: lint 2023-04-03 09:41:24 +02:00
TheRealLorenz
63525ec956 Rename function name 2023-03-25 17:33:01 +01:00
Aleksei Bavshin
93e340a081
feat(clock): support chrono Time Zone extensions.
Use chrono Calendars and Time Zones (P0355R7, P1466R3) when available
instead of the `date` library.
Verified with a patched build of a recent GCC 13 snapshot.
2023-01-21 02:18:44 -08:00
Aleksei Bavshin
ea17a66dfc
fix: compilation errors with cpp_std=c++20
There were two main issues with fmtlib and C++20 mode:

 - `fmt::format` defaults to compile-time argument checking and requires
   using `fmt::runtime(format_string)` to bypass that.
 - `std::format` implementation introduces conflicting declarations and
   we have to specify the namespace for all `format`/`format_to` calls.
2023-01-20 22:50:02 -08:00
Aleksei Bavshin
67efe1af89
refactor(clock): remove struct waybar_time
The structure was used to pass the locale instance to the date
formatter. All the supported versions of `fmt` are passing the locale
parameter via `FormatContext.locale()` so we can remove the struct and
simplify the code.

While we at it, drop `date::make_zoned` in favor of CTAD on a
`date::zoned_time` constructor.
2023-01-20 22:50:01 -08:00
herlev
54e04b5a30 Refactor rewriteTitle 2022-10-19 13:25:08 +02:00
Alex
8551c4bbe3 fix: lint 2022-10-17 09:19:00 +02:00
Alex
58362abfaf
Merge pull request #1630 from duxovni/pow_format 2022-10-17 09:16:47 +02:00
Mika Braunschweig
f86dff60e6
utils: add sanitize_str to encode '&' etc.
gtk requires some chars (<>&"') to be encoded for them to render
properly. `sanitize_str` sanitizes raw strings that have such chars and
returns a properly encoded string
2022-10-17 00:31:19 +02:00
Faye Duxovni
e14005a6aa Fix binary pow formatting for values between 1000 and 1024 2022-07-21 16:37:43 -04:00
Aleksei Bavshin
24a8332b62
fix: adapt to fmt 9.0.0 breaking changes 2022-07-13 22:36:32 -07:00
Alex
f2fcadbf62 refactor: lint 2022-04-06 08:37:19 +02:00
Alex
be1d2a02ca
Merge pull request #1422 from technic/fixes
minor string utils methods refactoring
2022-03-06 14:50:02 +01:00
Alex Maystrenko
d4da04a750 move Glib ustring format helper to utils
this formatter is useful for other modules
which want to print Glib exceptions messages
2022-02-05 21:26:48 +01:00
Alex Maystrenko
2697d432a4 ltrim and rtrim take argument by const-ref 2022-02-05 21:02:58 +01:00
Alex Maystrenko
061cb76fc4 make functions in header file inline
added header guard
now string utils can be used in any part of the project
2022-02-05 21:02:58 +01:00
Alex
1c08d26af0
Merge branch 'master' into master 2022-01-24 09:23:23 +01:00
Alex
667d0a45f4
Update command.hpp 2022-01-24 09:20:43 +01:00
Aleksei Bavshin
7f6bef2049
fix(util): make waybar_time formatter compatible with fmt 8.1.0
Stop using private implementation details of the `formatter<std::tm>`.
We never needed anything from the class besides the format specifier,
which is easily obtainable with public API.
2022-01-07 22:34:00 -08:00
Aleksei Bavshin
c0d84853ea
refactor(clock): extract waybar_time to util/waybar_time.hpp 2022-01-07 18:09:44 -08:00
mazunki
d22d6a4522 Merge branch 'master' of github.com:Alexays/Waybar 2022-01-08 01:02:57 +01:00
mazunki
bb7b376fa6 removed commented useless runtime errors 2021-11-24 01:37:21 +01:00
mazunki
b0eab5d793 maybe we shouldn't actually runtime error, but still doing a check 2021-11-09 19:03:15 +01:00
mazunki
17bb5643ae explicitly checking for errors to silence unused variable warnings when writing to fd 2021-11-09 18:38:07 +01:00
dmitry
8310700bbb Improve sway/language 2021-07-13 04:33:12 +03:00
John Helmert III
368e4813de
libfmt >=8.0.0 compatibility 2021-06-30 13:12:38 -05:00
Aleksei Bavshin
5da268077c
fix(util): protect std::condition_variable methods from pthread_cancel
The changes in GCC 11.x made `std::condition_variable` implementation
internals `noexcept`. `noexcept` is known to interact particularly bad
with `pthread_cancel`, i.e. `__cxxabiv1::__force_unwind` passing through
the `noexcept` call stack frame causes a `std::terminate` call and
immediate termination of the program

Digging through the GCC ML archives[1] lead me to the idea of patching
this with a few pthread_setcancelstate's. As bad as the solution is, it
seems to be the best we can do within C++17 limits and without major
rework.

[1]: https://gcc.gnu.org/legacy-ml/gcc/2017-08/msg00156.html
2021-06-12 12:56:44 -07:00
Mattéo Delabre
d8706af2ea
Terminate custom module scripts on exit
(Fixes #358.)

Subprocesses created for custom module scripts were previously left
running when the parent Waybar process exited. This patch sets the
parent-death signal of child processes (PR_SET_PDEATHSIG on Linux,
PROC_PDEATHSIG_CTL on FreeBSD) to SIGTERM.

Caveats:

* This uses Linux-specific or FreeBSD-specific calls. I don’t know if
  this project targets other systems?
* There is a possibility that Waybar exits after calling `fork()`, but
  before calling `prctl` to set the parent-death signal. In this case,
  the child will not receive the SIGTERM signal and will continue to
  run. I did not handle this case as I consider it quite unlikely, since
  module scripts are usually launched only when Waybar starts. Please
  let me know if you think it needs to be handled.

Testing:

* With `htop` open, run Waybar v0.9.5 with a custom module that has an
  `exec` script. Terminate the Waybar process and notice that the
  script’s subprocess stays alive and is now a child of the init
  process.
* Run Waybar with this patch and follow the same steps as above. Notice
  that this time the script’s subprocess terminates when the parent
  exits.
2021-02-12 21:14:46 +01:00
Aleksei Bavshin
38c29fc242
refactor(rfkill): poll rfkill events from Glib main loop
Open rfkill device only once per module.
Remove rfkill threads and use `Glib::signal_io` as a more efficient way
to poll the rfkill device.
Handle runtime errors from rfkill and stop polling of the device instead
of crashing waybar.
2021-02-09 21:27:19 -08:00
nullobsi
d2a1f41750
Use g_unichar_iswide to properly align calendar on CJK locales 2021-01-31 11:53:53 -08:00
Alex
f391186749
Revert "Replace lowercase "k" with uppercase "K" to make it look more consistent" 2020-12-25 09:28:05 +01:00
1sixth
7a0c0ca613
replace lowercase "k" with uppercase "K"
Other units are all uppercased, so using an uppercased "K" makes it look more consistent (especially when {bandwidthUpBits} or something like that is used).
2020-10-28 19:39:50 +08:00
Aleksei Bavshin
79883dbce4
feat(util): optimize SafeSignal for events from the main thread 2020-12-28 17:31:23 -08:00
Aleksei Bavshin
8a0e76c8d8
fix(util): avoid creating temporary functor for each event 2020-10-19 18:42:25 -07:00
Aleksei Bavshin
285a264aae
feat(util): SafeSignal class for cross-thread signals with arguments
Implement a wrapper over Glib::Dispatcher that passes the arguments to
the signal consumer via synchronized `std::queue`.
Arguments are always passed by value and the return type of the signal
is expected to be `void`.
2020-12-28 17:26:55 -08:00
Thorben Günther
9b41b95934
Fix crash with fmt 2020-08-10 20:53:29 +02:00
excellentname
c3359dec1b Replace signal handler with signal handling thread 2020-07-25 21:02:59 +10:00
excellentname
246f7bf555 Handle SIGCHLD for exec/forkExec
When forkExec is called it begins to ignore all SIGCHLD signals for
the rest of the progam's execution so that they are automatically
reaped. However, this means that subsequent waitpid calls in the exec
function will always fail. So instead handle SIGCHLD by reaping any
processes created by forkExec and ignoring all others so that they can be
handled directly by the exec function.
2020-07-21 12:36:48 +10:00
Alex
6e7f22ac3a fix: cancel thread and fix window close 2020-05-27 09:10:38 +02:00
Alex
1d92d78de7 refactor: prefer spdlog 2020-05-24 22:14:17 +02:00
Alex
eb624c929d fix: fmt format 2020-05-24 22:08:10 +02:00
Alex
7b4ded306b fix: restart-interval 2020-05-24 21:33:38 +02:00
Alex
9b9d13ab0d feat: execNoRead 2020-05-24 18:27:21 +02:00
Alex
6b32aca094 feat: debug cmd 2020-05-22 20:57:41 +02:00
Jan Beich
1dc557456e Add missing includes for libc++
In file included from ../src/modules/custom.cpp:1:
In file included from ../include/modules/custom.hpp:7:
../include/util/command.hpp:15:25: error: implicit instantiation of undefined template 'std::__1::array<char, 128>'
  std::array<char, 128> buffer = {0};
                        ^
../src/modules/pulseaudio.cpp:175:41: error: implicit instantiation of undefined template 'std::__1::array<std::__1::basic_string<char>, 9>'
static const std::array<std::string, 9> ports = {
                                        ^
/usr/include/c++/v1/__tuple:223:64: note: template is declared here
template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array;
                                                               ^
In file included from ../src/factory.cpp:1:
In file included from ../include/factory.hpp:8:
../include/modules/sway/workspaces.hpp:39:8: error: no template named 'unordered_map' in namespace 'std'
  std::unordered_map<std::string, Gtk::Button> buttons_;
  ~~~~~^
../src/factory.cpp:20:14: error: cannot initialize return object of type 'waybar::AModule *' with an rvalue of type 'waybar::modules::sway::Workspaces *'
      return new waybar::modules::sway::Workspaces(id, bar_, config_[name]);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-05-19 10:37:27 +00:00
Marc Radau
8a5c3af949
Merge pull request #8 from Alexays/master
Merge Alexays:master into marcplustwo:master
2020-04-05 16:13:56 +02:00