multiline strings in gadget.yaml defaults are mangled

Bug #1820060 reported by glancr team
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
snapd
Expired
Undecided
Unassigned

Bug Description

Expected behavior
Multiline strings for default configurations should be passed to the snap's configure hook with actual line breaks.

Actual behavior
Line breaks are passed as “\n” literals.

Context
I'm building an appliance image for the Raspberry Pi with a custom gadget snap. This snap contains default configuration for the mir-kiosk snap. The problematic config item is “display-config”: https://gitlab.com/glancr/gadget-snap-pi-kiosk/blob/master/gadget.yaml#L12

mir-kiosk allows injecting a complete display configuration file through this configuration item: https://github.com/MirServer/mir-kiosk/blob/ad041e6b19205acacaf9881568061d8fd5a5742e/snap/hooks/configure#L29 (See https://forum.snapcraft.io/t/prepare-device-hook-questions/9626/5)

If I place a file with the desired miral-kiosk.display in my Core user directory and run `snap set mir-kiosk display-config="$(cat ~/my-display-config-file)", the config file is written correctly by mir-kiosk's configure hook, and I can set one of the defined layouts through `snap set mir-kiosk display-layout={normal,right,left,inverted}` afterwards.

But when I create an image with ubuntu-image and my gadget snap, the initialization process errors during the configure hook for mir-kiosk:
2019-03-14T12:49:00Z ERROR run hook "configure": ERROR: 'right' is not a layout in /var/snap/mir-kiosk/1306/miral-kiosk.display

I can't inspect that file as it's instantly erased by snapd's rollback, but when I put my gadget.yaml source into a YAML parser like http://yaml-online-parser.appspot.com, it shows that my multiline string now contains the \n characters for line breaks. I suspect that snapd passes this directly on to the configure hook of mir-kiosk, which results in a config file with literal \n instead of proper line breaks, thus breaking the config file because mir-kiosk can't identify any layouts.

Zygmunt Krynicki (zyga)
Changed in snapd:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Have you tried with "|" to denote multiline string in the defaults section, e.g.

    yoursnap:
      multiline: |
        foo
        bar

This works in my limited unit test (I haven't tested it end-to-end though) and gives me a string with line breaks preserved (which is then fed internally to the config/hooks subsystem).

If that doesn't work, please provide the exact gadget.yaml you're using - the one you linked to if from your master branch, so it has changed already and doesn't reflect the description of the bug. If possible pastebin the complete file; even better would be a snap that exhibits the problem, so I can check it end-to-end.

Changed in snapd:
status: Triaged → Incomplete
Changed in snapd:
importance: Medium → Undecided
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for snapd because there has been no activity for 60 days.]

Changed in snapd:
status: Incomplete → Expired
Revision history for this message
glancr team (glancr) wrote :

Late, but for others who stumble across this: I tried with multiline string syntax (“|”) back in late 2019, but didn't work. But FWIW, I just re-checked with a core20-based gadget, latest snapd/mir-kiosk versions and this seems to work:

```yaml
defaults:
  # mir-kiosk
  rW4inp7UbJb1YBxWr6SVebxa3Yv7K1Vm:
    cursor: none
    show-splash: false
    display-config: |
      layouts:
        default:
          cards:
            - card-id: 0
              HDMI-A-1:
                orientation: right
        normal:
          cards:
            - card-id: 0
              HDMI-A-1:
                orientation: normal
        right:
          cards:
            - card-id: 0
              HDMI-A-1:
                orientation: right

          left:
            cards:
              - card-id: 0
                HDMI-A-1:
                  orientation: left

          inverted:
            cards:
              - card-id: 0
                HDMI-A-1:
                  orientation: inverted
```

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.