-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/snap-gpio-helper: add skeleton with re-exec support #15023
base: master
Are you sure you want to change the base?
Changes from 6 commits
44d70df
2566835
a74f848
51d0998
995a559
1f5f3b2
a82d3d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
||
/* | ||
* Copyright (C) 2025 Canonical Ltd | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
type cmdExportChardev struct { | ||
ChipLabels string `long:"chip-labels" description:"comma-separated list of source chip label(s) to match" required:"yes"` | ||
Lines uint `long:"line" description:"comma-separated list of gpio line(s) to export" required:"yes"` | ||
Gadget string `long:"gadget" description:"gadget snap name" required:"yes"` | ||
Slot string `long:"slot" description:"gpio-chardev slot name" required:"yes"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all are required so you can make them positional |
||
} | ||
|
||
func (c *cmdExportChardev) Execute(args []string) error { | ||
return errors.New("not implemented") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
||
/* | ||
* Copyright (C) 2025 Canonical Ltd | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package main | ||
|
||
import "errors" | ||
|
||
type cmdUnexportChardev struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the spec not mention There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for unexporting they are not really needed, but I could add them for completeness. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually the description for chip-labels and lines wouldn't make sense in the case of unexporting. ChipLabels string `long:"chip-labels" description:"comma-separated list of source chip label(s) to match" required:"yes"`
Lines uint `long:"line" description:"comma-separated list of gpio line(s) to unexport" required:"yes"` There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. options are marked as required, so you could make them positional like for export. Also, let's add all of them, such that even if the implementation was to change we have enough context provided in the input. |
||
Gadget string `long:"gadget" description:"gadget snap name" required:"yes"` | ||
Slot string `long:"slot" description:"gpio-chardev slot name" required:"yes"` | ||
} | ||
|
||
func (c *cmdUnexportChardev) Execute(args []string) error { | ||
return errors.New("not implemented") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
||
/* | ||
* Copyright (C) 2025 Canonical Ltd | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/jessevdk/go-flags" | ||
|
||
"github.com/snapcore/snapd/snapdtool" | ||
) | ||
|
||
type options struct { | ||
CmdExportChardev cmdExportChardev `command:"export-chardev"` | ||
CmdUnexportChardev cmdUnexportChardev `command:"unexport-chardev"` | ||
} | ||
|
||
func run(osArgs1 []string) error { | ||
var opts options | ||
p := flags.NewParser(&opts, flags.HelpFlag|flags.PassDoubleDash) | ||
|
||
if _, err := p.ParseArgs(osArgs1); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func main() { | ||
snapdtool.ExecInSnapdOrCoreSnap() | ||
|
||
if err := run(os.Args[1:]); err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
summary: Check that snap-helper-helper exists | ||
|
||
details: | | ||
The test verifies that snap-gpio-helper exists | ||
|
||
systems: [ubuntu-*] | ||
|
||
execute: | | ||
libexecdir=$(os.paths libexec-dir) | ||
if tests.info is-snapd-from-archive; then | ||
libexecdir="/snap/snapd/current$libexecdir" | ||
fi | ||
|
||
if [ ! -f "$libexecdir/snapd/snap-gpio-helper" ]; then | ||
exit 1 | ||
fi | ||
|
||
# Verify that snap-gpio-helper skeleton re-execs | ||
echo "Ensure snap-gpio-helper re-execs" | ||
set +e | ||
SNAPD_DEBUG=1 "$libexecdir/snapd/snap-gpio-helper" 2>&1 | MATCH "DEBUG: restarting into" | ||
set -e | ||
|
||
# TODO: add more checks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad, thanks!