fix(daemon): replace hardcoded username with $USER in systemd service#133
fix(daemon): replace hardcoded username with $USER in systemd service#133
Conversation
Co-authored-by: Le He <AnnatarHe@users.noreply.github.com>
Summary of ChangesHello @AnnatarHe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly identifies and fixes a bug in the systemd service file where a username was hardcoded. The fix replaces the hardcoded value with the $USER environment variable. My review includes a suggestion to further improve this by using a systemd-native specifier, which is more robust, efficient, and considered a best practice for systemd unit files.
| [Service] | ||
| Type=simple | ||
| ExecStart=/bin/sh -c 'exec $(getent passwd username | cut -d: -f7) -l -c "/usr/local/bin/shelltime-daemon"' | ||
| ExecStart=/bin/sh -c 'exec $(getent passwd $USER | cut -d: -f7) -l -c "/usr/local/bin/shelltime-daemon"' |
There was a problem hiding this comment.
While using $USER is an improvement over a hardcoded username, it's better practice and more robust to use systemd's own specifiers in unit files. The $USER variable might not always be set in all environments where the service could run, whereas systemd specifiers are guaranteed to be substituted correctly.
You can use the %s specifier, which expands to the user's configured shell from the user database. This simplifies the ExecStart directive significantly and makes it more efficient by avoiding the need to run /bin/sh, getent, and cut just to find the user's shell.
This is cleaner, more efficient, and less prone to errors.
ExecStart=%s -l -c "/usr/local/bin/shelltime-daemon"
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Fixes #132
Updated the systemd service file to use
$USERinstead of hardcodedusernamein the ExecStart command. This allows the service to dynamically resolve the current user's shell.Generated with Claude Code